gemd.json.gemd_json module
- class gemd.json.gemd_json.GEMDJson(scope: str = 'auto')
Bases:
object
Class that provides json load/dump functionality that is compatible with gemd objects.
The serialization and deserialization strategy implemented by this class is described in Serialization (with Graphs!)
scope: defines the scope to use for autogenerated UUIDs for objects without uids
- copy(obj)
Copy an object by dumping and then loading it.
- Parameters
obj (DictSerializable) – Object to copy
- Returns
A copy of obj.
- Return type
- dump(obj, fp, **kwargs)
Dump an object to a file, as a serialized string.
- Parameters
obj (DictSerializable or List[DictSerializable]) – Object(s) to dump
fp (file) – File to write to.
**kwargs (keyword args, optional) – Optional keyword arguments to pass to json.dumps().
- Return type
None
- dumps(obj, **kwargs) str
Serialize a gemd object, or container of them, into a json-formatting string.
- Parameters
obj (DictSerializable or List[DictSerializable]) – The object(s) to serialize to a string.
**kwargs (keyword args, optional) – Optional keyword arguments to pass to json.dumps().
- Returns
A string version of the serialized objects.
- Return type
str
- load(fp, **kwargs)
Load serialized string representation of an object from a file.
- Parameters
fp (file) – File to read.
**kwargs (keyword args, optional) – Optional keyword arguments to pass to json.loads().
- Returns
Deserialized object(s).
- Return type
DictSerializable or List[DictSerializable]
- loads(json_str: str, **kwargs)
Deserialize a json-formatted string into a gemd object.
- Parameters
json_str (str) – A string representing the serialized objects, like what is produced by
dumps()
.**kwargs (keyword args, optional) – Optional keyword arguments to pass to json.loads().
- Returns
Deserialized versions of the objects represented by json_str, with links turned back into pointers.
- Return type
DictSerializable or List[DictSerializable]
- raw_dumps(obj, **kwargs)
Serialize the object as-is, which could be as a nested object.
- Parameters
obj – Object to dump
**kwargs (keyword args, optional) – Optional keyword arguments to pass to json.dumps().
- Returns
A serialized string of obj, which could be nested
- Return type
str
- raw_loads(json_str, **kwargs)
Deserialize a json-formatted string with no context into a gemd object as-is.
- Parameters
json_str (str) – A string representing the serialized objects, like what is produced by
dumps()
.**kwargs (keyword args, optional) – Optional keyword arguments to pass to json.loads().
- Returns
Deserialized versions of the objects represented by json_str
- Return type
DictSerializable or List[DictSerializable]
- thin_dumps(obj, **kwargs)
Serialize a “thin” version of an object in which pointers are replaced by links.
- Parameters
obj – Object to dump
**kwargs (keyword args, optional) – Optional keyword arguments to pass to json.dumps().
- Returns
A serialized string of obj, with link_by_uid in place of pointers to other objects.
- Return type
str
- property scope: str
Return the default scope value.