expenvelope.json_serializer.SavesToJSON

class expenvelope.json_serializer.SavesToJSON[source]

Bases: object

Abstract class that, when implemented, gives the ability to save to and from JSON objects. Children must implement the _to_dict and _from_dict functions which convert back and forth between an instance and a dictionary representing that instance’s data. The data in such a dictionary may contain only standard json-serializable types (lists, dicts, ints, floats, strings, etc.) and other objects that implement the SavesToJSON interface,

Methods

duplicate()

Returns a copy of this object by serializing to and from JSON.

json_dumps()

Dump this object as a JSON string.

json_loads(s)

Load this object from a JSON string.

load_from_json(file_path)

Load this object from a JSON file with the given path.

save_to_json(file_path)

Save this object to a JSON file using the given path.

json_dumps() → str[source]

Dump this object as a JSON string. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.

save_to_json(file_path: str) → None[source]

Save this object to a JSON file using the given path. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.

Parameters

file_path – path for saving the file

classmethod json_loads(s: str) → T[source]

Load this object from a JSON string. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).

Parameters

s – a string representing this object in JSON format

classmethod load_from_json(file_path: str) → T[source]

Load this object from a JSON file with the given path. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).

Parameters

file_path – path for loading the file

duplicate() → T[source]

Returns a copy of this object by serializing to and from JSON.