json¶
Utility functions related to json.
Attributes¶
Classes¶
An error thrown when input data string does not represent a dictionary. |
|
An object to represent JSON data content. |
Functions¶
|
Dump a Python object to a json file. |
|
Load a Python object from a JSON file. |
Module Contents¶
- json.JsonDataSelf¶
- class json.JsonError¶
Bases:
e3.error.E3Error
- class json.JsonDataInvalidJsonError¶
Bases:
e3.error.E3ErrorAn error thrown when input data string does not represent a dictionary.
- class json.JsonData¶
Bases:
abc.ABCAn object to represent JSON data content.
- abstractmethod as_dict() dict[str, object]¶
Return the dict representation of this JSON data object.
- __eq__(other: object) bool¶
Check if this JSON data is identical to other.
- Parameters:
other – The object to compare this JSON data with.
- Returns:
A
boolset to True if both JSON data are identical, False if they are not, or if other is not aJsonDataobject.
- as_json() str¶
Return a JSON string representing this JSON data.
See also
python:json.dumps()
- classmethod from_dict(obj: dict) JsonDataSelf¶
Load a dictionary as a JSON data object.
- Parameters:
obj – The dictionary to initialize the JSON data object with.
- Returns:
A new
JsonDataobject initialized with values from the input dictionary.
- classmethod from_json(content: str) JsonDataSelf¶
Load a JSON string as a JSON data object.
As this method calls for
from_dict(), the input content string MUST represent a dictionary. If that’s not the case, aJsonDataInvalidJsonErroris thrown.- Parameters:
content – The JSON string to initialize the JSON data object with.
- Returns:
A new
JsonDataobject initialized with values from the input dictionary.- Raise:
JsonDataInvalidJsonErrorwhen content string does not represent a dictionary.
See also
- json.dump_to_json_file(path: str, obj: Any) None¶
Dump a Python object to a json file.
- Parameters:
path – path to the json file
obj – a Python object that can serialized to JSON
- json.load_from_json_file(path: str, default: Any = None, ignore_non_existing: bool = True) Any¶
Load a Python object from a JSON file.
- Parameters:
path – json file path
default – default value returned if ignore_non_existing is True and the specified file does not exist.
ignore_non_existing – if False raise JsonError if the file does not exist, otherwise return default value
- Returns:
a Python object