Transparent dumps
and loads
of numpy-arrays
. If a list is loaded
from a json
string it is given to numpy.array()
. If further, the
resulting array has a primitive type of either (int
, float
) it is
returned by loads
.
pip install json-numpy-sebastian-achim-mueller
to dump with json.dumps()
.
to load with json.loads()
.
import numpy
import json_numpy
obj = json_numpy.loads(s='{"a": [1.0, NaN]}')
assert isinstance(obj["a"], numpy.ndarray)
json_numpy.dumps(obj)
'{"a": [1.0, NaN]}'