pg.from_json_str¶
Accessible via pg.from_json_str, pg.symbolic.from_json_str.
- from_json_str(json_str, *, context=None, auto_import=True, convert_unknown=False, allow_partial=False, root_path=None, value_spec=None, **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.
context – JSON conversion context.
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.
convert_unknown –
If True, when a ‘_type’ is not registered and cannot be imported, PyGlove will create objects of:
pg.symbolic.UnknownType for unknown types;
pg.symbolic.UnknownTypedObject for objects of unknown types;
pg.symbolic.UnknownFunction for unknown functions;
pg.symbolic.UnknownMethod for unknown methods.
If False, TypeError will be raised.
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.
value_spec – The value spec for the symbolic list or dict.
**kwargs – Additional keyword arguments that will be passed to
pg.from_json.
- Returns:
A deserialized value.