JSON Drops Things Silently
luljs 2009 still worksSerialize a user profile and some fields vanish.
In 2026: Still works. JSON.stringify omits any property whose value is undefined or a function, and it turns NaN and Infinity into null. So a profile with an undefined avatar, a greet method, and a NaN score serializes to the name, a null score and the wins count, with the avatar and method gone. Round-tripping data through JSON quietly loses these.
Where it came from: JSON.stringify omits undefined and function values and maps NaN and Infinity to null, as MDN documents. MDN ↗
<script>
var profile = { name: "Ada", avatar: undefined, greet: function () {}, score: NaN, wins: 3 };
document.write('<p>Profile: <code>{ name, avatar: undefined, greet: function, score: NaN, wins }</code></p>');
document.write('<p><code>JSON.stringify(profile)</code> is <b>' + JSON.stringify(profile) + '</b></p>');
document.write('<p>undefined and functions are dropped; NaN becomes null.</p>');
</script>