pg.from_json_str¶
Accessible via pg.from_json_str, pg.symbolic.from_json_str.
- from_json_str(json_str, *, allow_partial=False, root_path=None, auto_import=True, auto_dict=False, **kwargs)[source]¶
Deserialize (maybe) symbolic object from JSON string.
Example:
@pg.members([ ('x', pg.typing.Any()) ]) class A(pg.Object): pass a1 = A(1) json_str = a1.to_json_str() a2 = pg.from_json_str(json_str) assert pg.eq(a1, a2)
- Return type:
- Parameters:
json_str – JSON string.
allow_partial – If True, allow a partial symbolic object to be created. Otherwise error will be raised on partial value.
root_path – The symbolic path used for the deserialized root object.
auto_import – If True, when a ‘_type’ is not registered, PyGlove will identify its parent module and automatically import it. For example, if the type is ‘foo.bar.A’, PyGlove will try to import ‘foo.bar’ and find the class ‘A’ within the imported module.
auto_dict – If True, dict with ‘_type’ that cannot be loaded will remain as dict, with ‘_type’ renamed to ‘type_name’.
**kwargs – Additional keyword arguments that will be passed to
pg.from_json.
- Returns:
A deserialized value.