@@ -561,7 +561,12 @@ def json_description(self) -> str:
561561 """
562562 return self .__class__ .__doc__ or "Generated with PyCardano"
563563
564- def to_json (self , key_type : Optional [str ] = None , description : Optional [str ] = None ) -> str :
564+ def to_json (
565+ self ,
566+ key_type : Optional [str ] = None ,
567+ description : Optional [str ] = None ,
568+ ** kwargs ,
569+ ) -> str :
565570 """
566571 Convert the CBORSerializable object to a JSON string containing type, description, and CBOR hex.
567572
@@ -570,17 +575,21 @@ def to_json(self, key_type: Optional[str] = None, description: Optional[str] = N
570575 Args:
571576 key_type (str): The type to use in the JSON output. Defaults to the class name.
572577 description (str): The description to use in the JSON output. Defaults to the class docstring.
578+ **kwargs: Extra key word arguments to be passed to `json.dumps()`
573579
574580 Returns:
575581 str: The JSON string representation of the object.
576582 """
583+ if "indent" not in kwargs :
584+ kwargs ["indent" ] = 2
585+
577586 return json .dumps (
578587 {
579588 "type" : key_type or self .json_type ,
580589 "description" : description or self .json_description ,
581590 "cborHex" : self .to_cbor_hex (),
582591 },
583- indent = 2 ,
592+ ** kwargs ,
584593 )
585594
586595 @classmethod
@@ -613,6 +622,7 @@ def save(
613622 path : str ,
614623 key_type : Optional [str ] = None ,
615624 description : Optional [str ] = None ,
625+ ** kwargs ,
616626 ):
617627 """
618628 Save the CBORSerializable object to a file in JSON format.
@@ -624,14 +634,15 @@ def save(
624634 path (str): The file path to save the object to.
625635 key_type (str, optional): The type to use in the JSON output. Defaults to the class name.
626636 description (str, optional): The description to use in the JSON output. Defaults to the class docstring.
637+ **kwargs: Extra key word arguments to be passed to `json.dumps()`
627638
628639 Raises:
629640 IOError: If the file already exists and is not empty.
630641 """
631642 if os .path .isfile (path ) and os .stat (path ).st_size > 0 :
632643 raise IOError (f"File { path } already exists!" )
633644 with open (path , "w" ) as f :
634- f .write (self .to_json (key_type = key_type , description = description ))
645+ f .write (self .to_json (key_type = key_type , description = description , ** kwargs ))
635646
636647 @classmethod
637648 def load (cls , path : str ):
0 commit comments