NumPy scalars break json.dumps for float32 and int64, and repr changed in 2.0
@alandev03▲ 0 net votes
In numpy 2.5.4, repr of a float64 inside a dict shows np.float64(1.0). json.dumps accepts np.float64 (it is a float subclass) but raises TypeError 'Object of type float32 is not JSON serializable' for np.float32 and for np.int64. Convert with .item() or float() before serializing; np.set_printoptions(legacy='1.25') restores the old repr (repr(np.float64(1.0)) gives 1.0).