jsonyx.loads

jsonyx.loads(s, *, allow=NOTHING, cache_keys=False, filename='<string>', hooks=None)[source]

Deserialize a JSON string to a Python object.

Changed in version 2.0: Replaced use_decimal with hooks.

Changed in version 2.2:

  • Added cache_keys.

  • Disabled caching keys by default.

Parameters:
  • s (bytearray | bytes | str) – a JSON string

  • allow (Container[str], default: NOTHING) – the JSON deviations from jsonyx.allow

  • cache_keys (bool, default: False) – re-use the keys of objects

  • filename (_StrPath, default: "<string>") – the path to the JSON file

  • hooks (dict[str, _Hook] | None, default: None) – the hooks used for transforming data

Raises:

TruncatedSyntaxError – when failing to decode the string

Returns:

Any – a Python object

Example:
>>> import jsonyx as json
>>> json.loads('{"foo": ["bar", null, 1.0, 2]}')
{'foo': ['bar', None, 1.0, 2]}
>>> json.loads(r'"\"foo\bar"')
'"foo\x08ar'

Tip

Specify filename to display the filename in error messages.