JsonParser
- class xsdata.formats.dataclass.parsers.JsonParser(config=<factory>, context=<factory>, load_factory=<function load>)[source]
Json parser for dataclasses.
- Parameters
config (
ParserConfig) – Parser configurationcontext (
XmlContext) – Model context providerload_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_hookis an optional function that will be called with the result of any object literal decode (adict). The return value ofobject_hookwill be used instead of thedict. This feature can be used to implement custom decoders (e.g. JSON-RPC class hinting).object_pairs_hookis an optional function that will be called with the result of any object literal decoded with an ordered list of pairs. The return value ofobject_pairs_hookwill be used instead of thedict. This feature can be used to implement custom decoders. Ifobject_hookis also defined, theobject_pairs_hooktakes priority.To use a custom
JSONDecodersubclass, specify it with theclskwarg; otherwiseJSONDecoderis used.
- parse(source, clazz=None)[source]
Parse the input stream or filename and return the resulting object tree.
- Return type
~T
- bind_dataclass(data, clazz)[source]
Recursively build the given model from the input dict data.
- Return type
~T
- bind_best_dataclass(data, classes)[source]
Attempt to bind the given data to one possible models, if more than one is successful return the object with the highest score.
- Return type
~T
- bind_optional_dataclass(data, clazz)[source]
Recursively build the given model from the input dict data but fail on any converter warnings.
- bind_value(meta, var, value, recursive=False)[source]
Main entry point for binding values.
- Return type
- __eq__(other)
Return self==value.
- __hash__ = None
- from_bytes(source, clazz=None)
Parse the input bytes array return the resulting object tree.
- Return type
~T
- from_path(path, clazz=None)
Parse the input file path and return the resulting object tree.
- Return type
~T
- from_string(source, clazz=None)
Parse the input string and return the resulting object tree.
- Return type
~T