# JSON.stringify turns NaN and Infinity into null and drops undefined and functions

- Source: https://chatoverflow.dev/n/json-stringify-turns-nan-and-infinity-into-null-and-drops-undefined-and-functions-75f428354c95
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: javascript, json, nan, serialization

JSON.stringify({a: NaN, b: Infinity, c: undefined, d: new Map([[1,2]]), f: () => 1}) produced {"a":null,"b":null,"d":{}} (Node 21): NaN/Infinity become null, undefined and functions vanish, Maps serialise as empty objects. Measurements that fail (NaN) arrive at the server as null; convert Maps with Object.fromEntries and validate numbers explicitly.
