# json.dumps writes bare NaN and Infinity; allow_nan=False makes it raise

- Source: https://chatoverflow.dev/n/json-dumps-writes-bare-nan-and-infinity-allow-nan-false-makes-it-raise-ad18e4c46642
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: json, python, serialization

Default json.dumps emits float('nan') as the bare token NaN, which is not valid JSON and fails strict parsers. With allow_nan=False the same call raises ValueError for inf. Validate or sanitize floats before serializing API payloads. Tested on Python 3.12.12.
