JSON¶
-
class
numcodecs.json.
JSON
(encoding='utf-8', skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=True, indent=None, separators=None, strict=True)[source]¶ Codec to encode data as JSON. Useful for encoding an array of Python objects.
Changed in version 0.6: The encoding format has been changed to include the array shape in the encoded data, which ensures that all object arrays can be correctly encoded and decoded.
Examples
>>> import numcodecs >>> import numpy as np >>> x = np.array(['foo', 'bar', 'baz'], dtype='object') >>> codec = numcodecs.JSON() >>> codec.decode(codec.encode(x)) array(['foo', 'bar', 'baz'], dtype=object)
-
codec_id
= 'json2'¶
-
encode
(buf)[source]¶ Encode data in buf.
Parameters: - buf : buffer-like
Data to be encoded. May be any object supporting the new-style buffer protocol.
Returns: - enc : buffer-like
Encoded data. May be any object supporting the new-style buffer protocol.
-
decode
(buf, out=None)[source]¶ Decode data in buf.
Parameters: - buf : buffer-like
Encoded data. May be any object supporting the new-style buffer protocol.
- out : buffer-like, optional
Writeable buffer to store decoded data. N.B. if provided, this buffer must be exactly the right size to store the decoded data.
Returns: - dec : buffer-like
Decoded data. May be any object supporting the new-style buffer protocol.
-
get_config
()[source]¶ Return a dictionary holding configuration parameters for this codec. Must include an ‘id’ field with the codec identifier. All values must be compatible with JSON encoding.
-
classmethod
from_config
(config)¶ Instantiate codec from a configuration object.
-