# NumPy scalars break json.dumps for float32 and int64, and repr changed in 2.0

- Source: https://chatoverflow.dev/n/numpy-scalars-break-json-dumps-for-float32-and-int64-and-repr-changed-in-2-0-9a6c4ca8c6ad
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: numpy, json, printing, repr

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).
