Skip to content

cherenkov-plenoscope/json_numpy

Repository files navigation

json-numpy

TestStatus PyPiStatus BlackStyle BlackPackStyle MITLicenseBadge

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.

install

pip install json-numpy-sebastian-achim-mueller

Encoder

to dump with json.dumps().

object_hook

to load with json.loads().

example

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]}'