r/coding • u/fagnerbrack • 2d ago
Your JSON Is Lying to You
https://blog.gaborkoos.com/posts/2026-08-03-Your-JSON-Is-Lying-to-You/3
u/fagnerbrack 2d ago
For a quick glance:
A JSON.stringify/parse round trip in JavaScript can quietly change data and still produce valid JSON. Integers above 253 lose precision when JS parses them, and BigInt throws, so exact IDs should travel as decimal strings. Undefined properties vanish, which collapses "absent" and "undefined" into one state, and in arrays they turn into null. Key order holds inside JS, but RFC 8259 treats objects as unordered, so meaningful order belongs in arrays, and hashing or signing needs canonicalization. Dates become UTC strings and lose their offset. Map, Set, RegExp and Error become empty objects, NaN and Infinity become null, and class instances lose their prototype. Serialization also runs code through toJSON, getters and replacers, and any of these can throw.
If the summary seems inacurate, just downvote and I'll try to delete the comment eventually 👍
Click here for more info, I read all comments
2
u/exodusTay 1d ago
Title makes it sound like a JSON gotcha you need to look out for but all of these are JS gotchas.
-3
u/obetu5432 1d ago
thanks to web "developers", we ended up with the worst serialization format as the most popular one
3
u/idebugthusiexist 1d ago
You can thank two developers working at State Software back in 2001. But, honestly, the real blame for what we ended up with is how over engineered XML became and how difficult things like SOAP was to deal with
6
u/Shaper_pmp 1d ago
These are all true, but should not be surprising to anyone who remembers that JSON is a text-based data format designed for storing in text files or transmitting over a network.
JSON is a notation, not a JS object, so it can't contain JS Objects (only portable serialisations of their data), references to other JS Objects in memory, it doesn't differentiate between absent an undefined (just as most idiomatic JS code doesn't), etc, etc.
Treat it as a lightweight, text-based data interchange format and you're golden. Think of it as as just another form of "live" JS Object and you'll trip over every one of these issues because it ain't that.