xsdata.formats.dataclass.parsers.json module

class xsdata.formats.dataclass.parsers.json.JsonParser(context=<factory>)[source]

Bases: xsdata.formats.bindings.AbstractParser

Json parsing and binding for dataclasses.

Parameters

context (XmlContext) – Model metadata builder

context: xsdata.formats.dataclass.context.XmlContext
from_path(path, clazz)[source]

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

Parameters
Return type

~T

parse(source, clazz)[source]

Parse the JSON input stream and return the resulting object tree.

Parameters
  • source (BytesIO) –

  • clazz (Type[~T]) –

Return type

~T

parse_context(data, clazz)[source]

Recursively build the given model from the input dict data.

Raises

ParserError – When parsing fails for any reason

Parameters
Return type

~T

bind_value(var, value)[source]

Bind value according to the class var.

The return value can be: - a dataclass instance - a dictionary with unknown attributes - a list of unknown elements - an enumeration - a primitive value

Parameters
Return type

Any

bind_wildcard(value)[source]
Parameters

value (Any) –

Return type

Any

bind_choice(value, var)[source]
Parameters
Return type

Any

static get_value(data, var)[source]

Find the var value in the given dictionary or return the default var value.

Parameters
Return type

Any

class xsdata.formats.dataclass.parsers.json.DictConverter(context=<factory>)[source]

Bases: xsdata.formats.dataclass.parsers.json.JsonParser

Parameters

context (XmlContext) –

convert(data, clazz)[source]
Parameters
Return type

~T

context: xsdata.formats.dataclass.context.XmlContext