pg.utils.from_json¶
Accessible via pg.utils.from_json.
- from_json(json_value, *, context=None, auto_import=True, convert_unknown=False, trusted=True, **kwargs)[source]¶
Deserializes a (maybe) JSONConvertible value from JSON value.
- Return type:
- 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.
trusted – If True (default, backward-compatible), the input JSON is treated as coming from a trusted source and arbitrary symbol resolution (function/method/type gadgets, auto_import via _load_symbol, and opaque-object pickle) is allowed. If False, the input is treated as untrusted so symbol resolution is restricted to the registry allowlist only and opaque-object pickle is disabled. See b/522141119.
**kwargs – Keyword arguments that will be passed to JSONConvertible.__init__.
- Returns:
Deserialized value.