JsonParser#
- class xsdata.formats.dataclass.parsers.JsonParser(config=<factory>, context=<factory>, load_factory=<function load>)[source]#
Json parser for data classes.
- Parameters:
config (
ParserConfig
) – Parser configurationcontext (
XmlContext
) – The models context instanceload_factory (
Callable
) – Json loader factory
- 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 into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.
- verify_type(clazz, data)[source]#
Verify the given data matches the given clazz.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.
- bind_dataclass(data, clazz)[source]#
Create a new instance of the given class type with the given data.
- bind_derived_dataclass(data, clazz)[source]#
Bind the input data to the given class type.
Examples
>>> { "qname": "foo", "type": "my:type", "value": {"prop": "value"} }
- bind_best_dataclass(data, classes)[source]#
Bind the input data to all the given classes and return best match.
- bind_optional_dataclass(data, clazz)[source]#
Bind the input data to the given class type.
This is a strict process, if there is any warning the process returns None. This method is used to test if te data fit into the class type.
- bind_derived_value(meta, var, data)[source]#
Bind derived data entrypoint.
- The data is representation of a derived element, e.g. {
“qname”: “foo”, “type”: “my:type” “value”: Any
}
The data value can be a primitive value or a complex value.
- classmethod find_var(xml_vars, local_name, is_list=False)[source]#
Match the name to a xml variable.
- __eq__(other)#
Return self==value.
- __hash__ = None#
- from_bytes(source, clazz=None)#
Parse the input source bytes object into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.
- from_path(path, clazz=None)#
Parse the input file into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.
- from_string(source, clazz=None)#
Parse the input source string into the target class type.
If no clazz is provided, the binding context will try to locate it from imported dataclasses.