3.1.1.5. gemd.json package

Submodules

Module contents

gemd JSON support, which provides a drop-in replacement for json.

This module provides the four main python json methods:

  • dump() for serializing python and gemd objects to a JSON file

  • load() for deserializing python and gemd objects from a JSON file

  • dumps() for serializing python and gemd objects into a String

  • loads() for deserializing python and gemd objects from a String

These methods should provide drop-in support for serialization and deserialization of gemd-containing data structures by replacing imports of json with those of gemd.json.

It also provides convenience imports of GEMDEncoder and GEMDJson. These classes can be used by developers to integrate gemd with other tools by extending the JSON support provided here to those tools.

gemd.json.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

gemd.json.dumps(obj, **kwargs)

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

gemd.json.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]

gemd.json.loads(json_str, **kwargs)

Deserialize a json-formatted string into a gemd object.

Parameters
  • json_str (str) – A string representing the serialized objects, such as 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 python object references.

Return type

DictSerializable or List[DictSerializable]