pg.from_json

Accessible via pg.from_json, pg.symbolic.from_json.

from_json(json_value, *, allow_partial=False, root_path=None, force_dict=False, **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:

Any

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.

  • force_dict – If True, “_type” keys will be stripped before loading. As a result, JSONConvertible objects will be returned as 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.