plaid.utils.json_codec¶
plaid.utils.json_codec
¶
Generic JSON value codec with fast array encoding.
This module serializes arbitrary JSON-shaped values to a language-neutral payload. NumPy arrays are encoded as base64 little-endian C-contiguous bytes with explicit dtype and shape metadata, so the payload can be decoded from Python, MATLAB, R, JavaScript, or any language with base64 and typed-array support. Scalars pass through unchanged, and lists and dictionaries are encoded element-wise.
plaid.utils.json_codec.encode_json_value
¶
Recursively encode a value into a JSON-compatible structure.
Scalars pass through unchanged. Lists and tuples are encoded element-wise. Dictionaries are encoded value-wise with string keys. NumPy scalars, NumPy arrays, and bytes are encoded with the portable base64 schema.
Parameters:
-
value(Any) –Value to encode.
Returns:
-
Any–A JSON-compatible representation of
value.
Raises:
-
TypeError–If a leaf value type is not supported.
Source code in plaid/utils/json_codec.py
plaid.utils.json_codec.decode_json_value
¶
Recursively decode a value produced by :func:encode_json_value.
Encoded NumPy arrays and bytes are detected by their kind marker and
restored. Other dictionaries and lists are decoded element-wise, and
scalars pass through unchanged.
Parameters:
-
value(Any) –Value to decode.
Returns:
-
Any–The decoded value.
Source code in plaid/utils/json_codec.py
plaid.utils.json_codec.encode_leaf_value
¶
Encode a single leaf value (scalar, NumPy scalar/array, or bytes).
Parameters:
-
value(Any) –Leaf value to encode.
Returns:
-
Any–A JSON-compatible representation of
value.
Raises:
-
TypeError–If the value type is not supported.
Source code in plaid/utils/json_codec.py
plaid.utils.json_codec.decode_leaf_value
¶
Decode a single leaf value produced by :func:encode_leaf_value.
Parameters:
-
value(Any) –Leaf value to decode.
Returns:
-
Any–The decoded value.