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_hook
is an optional function that will be called with the result of any object literal decode (adict
). The return value ofobject_hook
will be used instead of thedict
. 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 ofobject_pairs_hook
will be used instead of thedict
. This feature can be used to implement custom decoders. Ifobject_hook
is also defined, theobject_pairs_hook
takes priority.To use a custom
JSONDecoder
subclass, specify it with thecls
kwarg; otherwiseJSONDecoder
is used.
- parse(source, clazz=None)[source]¶
Parse the input stream or filename and return the resulting object tree.
- 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.
- bind_optional_dataclass(data, clazz)[source]¶
Recursively build the given model from the input dict data but fail on any converter warnings.
- bind_derived_value(meta, var, data)[source]¶
Bind derived element entry point.
- Parameters
- Return type
- from_bytes(source, clazz=None)¶
Parse the input bytes array return the resulting object tree.
- from_path(path, clazz=None)¶
Parse the input file path and return the resulting object tree.