pg.from_json¶
Accessible via pg.from_json, pg.symbolic.from_json.
- from_json(json_value, *, allow_partial=False, root_path=None, auto_import=True, auto_dict=False, value_spec=None, **kwargs)[source]¶
Deserializes a (maybe) symbolic value from JSON value.
Example:
@pg.members([ ('x', pg.typing.Any()) ]) class A(pg.Object): pass a1 = A(1) json = a1.to_json() a2 = pg.from_json(json) assert pg.eq(a1, a2)
- Return type:
- Parameters:
json_value – Input JSON value.
allow_partial – Whether to allow elements of the list to be partial.
root_path – KeyPath of loaded object in its object tree.
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’.
value_spec – The value spec for the symbolic list or dict.
**kwargs – Allow passing through keyword arguments to from_json of specific types.
- Returns:
Deserialized value, which is * pg.Dict for dict. * pg.List for list. * symbolic.Object for dict with ‘_type’ property. * value itself.