Why are some numpy datatypes JSON serializable and others not? Why are some numpy datatypes JSON serializable and others not? numpy numpy

Why are some numpy datatypes JSON serializable and others not?


The data types that are JSON serializable are all Python built-ins:

>>> np.int is intTrue>>> np.float is floatTrue>>> np.bool is boolTrue

So all NumPy data types that you show are not JSON serializable. At least is consistent.

np.float_ is the same as np.float64 (tested on MacOS):

>>> np.float_ is np.float64True

The help says:

np.float64

64-bit floating-point number. Character code 'd'. Python float compatible.

Whereas:

np.float32

32-bit floating-point number. Character code 'f'. C float compatible.

So, Python float compatible types work with json.dumps(), but C compatible ones don't.