File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,26 @@ def to_file(self, path: str):
485485 # we prefer key ordering according to the fields in the model
486486 json .dump (self .dict (), f , sort_keys = False , indent = 4 )
487487
488+ @classmethod
489+ def from_string (cls , text : str ) -> "Self" :
490+ """
491+ Load model from json string.
492+ """
493+ import json
494+
495+ data = json .loads (text )
496+ obj = cls (** data )
497+ return obj
498+
499+ def to_string (self ) -> str :
500+ """
501+ Dump model to a json string.
502+ """
503+ import json
504+
505+ result = json .dumps (self .dict (), sort_keys = False , indent = 4 )
506+ return result
507+
488508 def do_snapshot (self ):
489509 """
490510 Save ``self.dict()`` result as a new starting point for detecting changes in the object data.
You can’t perform that action at this time.
0 commit comments