JsonParser

class xsdata.formats.dataclass.parsers.JsonParser(context=<factory>, load_factory=<function load>)[source]

Json parser for dataclasses.

Parameters
  • context (XmlContext) – Model context provider

  • load_factory (Callable) – Replace the default json.load call with another implementation

load_factory(*, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)

Deserialize fp (a .read()-supporting file-like object containing a JSON document) to a Python object.

object_hook is an optional function that will be called with the result of any object literal decode (a dict). The return value of object_hook will be used instead of the dict. This feature can be used to implement custom decoders (e.g. JSON-RPC class hinting).

object_pairs_hook is an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value of object_pairs_hook will be used instead of the dict. This feature can be used to implement custom decoders. If object_hook is also defined, the object_pairs_hook takes priority.

To use a custom JSONDecoder subclass, specify it with the cls kwarg; otherwise JSONDecoder is used.

parse(source, clazz=None)[source]

Parse the input stream or filename and return the resulting object tree.

Parameters
Return type

~T

bind_value(var, value)[source]

Bind value according to the class var.

Parameters
Return type

Any

bind_dataclass(data, clazz)[source]

Recursively build the given model from the input dict data.

Parameters
Return type

~T

maybe_bind_dataclass(data, clazz)[source]

Recursively build the given model from the input dict data but fail on any converter warnings.

Parameters
Return type

Optional[~T]

bind_dataclass_union(value, var)[source]

Bind data to all possible models and return the best candidate.

Parameters
Return type

Any

bind_wildcard(value)[source]

Bind data to a wildcard model.

Parameters

value (Any) –

Return type

Any

bind_choice(value, var)[source]

Bind data to one of the choice models.

Parameters
Return type

Any

bind_choice_simple(value, var)[source]

Bind data to one of the simple choice types and return the first that succeeds.

Parameters
Return type

Any

bind_choice_generic(value, var)[source]

Bind data to a either a derived or a user derived model.

Parameters
Return type

Any

bind_choice_dataclass(value, var)[source]

Bind data to the best matching choice model.

Parameters
Return type

Any

classmethod parse_value(value, types, default, tokens, fmt)[source]

Convert any value to one of the given var types.

Parameters
Return type

Any

from_bytes(source, clazz=None)

Parse the input bytes array return the resulting object tree.

Parameters
Return type

~T

from_path(path, clazz=None)

Parse the input file path and return the resulting object tree.

Parameters
Return type

~T

from_string(source, clazz=None)

Parse the input string and return the resulting object tree.

Parameters
Return type

~T