pg.utils.from_json

Accessible via pg.utils.from_json.

from_json(json_value, *, context=None, auto_import=True, convert_unknown=False, **kwargs)[source]

Deserializes a (maybe) JSONConvertible value from JSON value.

Return type:

Any

Parameters:
  • json_value – Input JSON value.

  • context – Serialization 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.

  • **kwargs – Keyword arguments that will be passed to JSONConvertible.__init__.

Returns:

Deserialized value.