myjson

Module Contents

Classes

Functions

Attributes

EXCLUDED_TAGS
getExecPath()[source]
class SaveableObject[source]

Abstract class for dynamically type-hinted objects. This class is to solve the special case where the exact type of an attribute is not known before runtime, yet has to be saved.

get_additional_attributes_to_save()[source]

Return list of attributes corresponding to object, whose type cannot be determined statically (e.g. topology change)

get_additional_attributes_to_save_list()[source]

Same behavior as get_additional_attributes_to_save, but where the attributes contains list of unknown items

_isclass(theObject)[source]

Extends the default isclass method with typing

get_type_class(typ)[source]

Get the type of the class. used to compare objects from Typing.

_get_object_class(theObj)[source]
_get_object_module(theObj)[source]
_object_to_FQCN(theobj)[source]

Gets module path of object

_find_class(moduleName, className)[source]
json_to_obj(json_dict)[source]

Convenience class to create object from dictionary. Only works if CLASS_TAG is valid

Parameters:

json_dict – dictionary loaded from a json file.

Raises:
  • TypeError – if class can not be found
  • KeyError – if CLASS_TAG not present in dictionary
json_to_obj_safe(json_dict, cls)[source]

Safe class to create object from dictionary.

Parameters:
  • json_dict – dictionary loaded from a json file
  • cls – class object to instantiate with dictionary
_instantiates_annotated_object(_json_dict, _cls)[source]
_get_annotations(theObj)[source]

Return annotated attributes (theObj being the type of the object)

obj_to_json(theObj)[source]

Extract the json dictionary from the object. The data saved are automatically detected, using typehints. ex: x: int=5 will be saved, x=5 won’t. Inheritance of annotation is managed by this function

_get_attributes_to_save(theObj)[source]

Return list (attribute, is_first)

get_json_module_tree_from_dict(jsonDict)[source]

Return dict containing {CLASS_TAG: “class_name”, MODULE_TAG: “module_name”, “attribute1”:{“class_name”: “module_name”, …}}

remove_module_tree_from_string(theStr)[source]

Used to compress string by removing __module__ and __class__ entries (used with get_json_module_tree_from_dict)

apply_module_tree_to_dict(nestedTree, nestedObject, raiseError=False)[source]

Restore __module__ and __class__ entries from nestedTree in nestedDict

encode_str_json(theStr)[source]
decode_str_json(theStr)[source]