JSON encoding/decoding for Numpy arrays and scalars
Low maintenance activity. Last release 17 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install json-numpyjson-numpy
Description
json-numpy provides lossless and quick JSON encoding/decoding for NumPy arrays and scalars.
json-numpy follows Semantic Versioning.
Installation
json-numpy can be installed using pip:
$ pip install json-numpy
Usage
For a quick start, json_numpy can be used as a simple drop-in replacement of the built-in json module.
The dump(), load(), dumps() and loads() methods are implemented by wrapping the original methods and replacing the default encoder and decoder.
More information on the usage can be found in the json module's documentation.
import numpy as np
import json_numpy
arr = np.array([0, 1, 2])
encoded_arr_str = json_numpy.dumps(arr)
decoded_arr = json_numpy.loads(encoded_arr_str)
Another way of using json_numpy is to explicitly use the provided encoder and decoder functions in conjunction with the json module.
import json
import numpy as np
from json_numpy import default, object_hook
arr = np.array([0, 1, 2])
encoded_arr_str = json.dumps(arr, default=default)
decoded_arr = json.loads(encoded_arr_str, object_hook=object_hook)
Finally, the last way of using json_numpy is by monkey patching the json module after importing it first: