:py:mod:`pygsti.serialization.jsoncodec` ======================================== .. py:module:: pygsti.serialization.jsoncodec .. autoapi-nested-parse:: Defines JSON-format encoding and decoding functions Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: pygsti.serialization.jsoncodec.encode_obj pygsti.serialization.jsoncodec.decode_obj .. py:function:: encode_obj(py_obj, binary) Returns JSON-compatible version of `py_obj`. Constructs in-memory a JSON-format-compatible copy of the Python object `py_obj`, handling pyGSTi objects appropriately. When `binary=False`, the output must contain only ASCII-compatible strings (no 'bytes'), otherwise the output is allowed to contain non-ASCII string values (OK for binary formats like MSGPACK and BSON). Parameters ---------- py_obj : object The object to encode. binary : bool Whether the output is allowed to have binary-mode strings or not. Returns ------- object A JSON-format compatible object. Usually a dict, list, or string. .. py:function:: decode_obj(json_obj, binary) Inverse of :func:`encode_obj`. Decodes the JSON-compatible `json_obj` object into the original Python object that was encoded. Parameters ---------- json_obj : object The JSON-compabtible object to decode. Note that this is NOT a JSON string, but rather the object that would be decoded from such a string (by `json.loads`, for instance). binary : bool Whether `json_obj` is a binary format or not. If so, then the decoding expects all strings to be binary strings i.e. `b'name'` instead of just `'name'`. The value of this argument should match that used in the original call to :func:`encode_obj`. Returns ------- object A Python object.