Developer Utilities · 8 min read
Why JSON.parse() Breaks 64-Bit IDs, Decimals and Duplicate Keys
Standard JavaScript JSON.parse() rounds 64-bit Snowflake IDs, strips 1.0 decimal precision, and silently drops duplicate object keys. Learn how RFC 8259 tokenizers prevent subtle API debugging mistakes.
Published
Key takeaways
- JavaScript IEEE 754 numbers lose precision above 2^53 - 1 (9,007,199,254,740,991), silently mutating 64-bit database and Snowflake IDs.
- A lossless RFC 8259 tokenizer/AST preserves exact numeric lexemes (1.0, 1e-6, 64-bit ints), original key order, and duplicate keys.
- Formatting multi-megabyte API responses inside a dedicated Web Worker prevents main-thread tab freezes.
In this guide
The Silent 64-Bit Integer Rounding Bug in JavaScript
Most online JSON formatters are a three-line wrapper around JSON.stringify(JSON.parse(input), null, 2). For small configuration snippets, that shortcut seems harmless — until you paste a real API payload from Stripe, Discord, Twitter/X, PostgreSQL BIGINT columns, or a distributed Snowflake ID generator.
JavaScript stores every number as an IEEE 754 64-bit double-precision floating-point value. Doubles only have 53 bits of significand precision, meaning integers larger than Number.MAX_SAFE_INTEGER (2⁵³ − 1 = 9,007,199,254,740,991) cannot be represented accurately. When JSON.parse() encounters a 64-bit integer above that ceiling, it does not throw an error — it silently rounds the trailing digits to the nearest representable float!
// Raw API response containing a 64-bit Snowflake order ID:
const raw = '{"orderId": 9007199254740993, "amount": 49.00, "role": "guest", "role": "admin"}';
// Standard JavaScript JSON.parse() silently corrupts three things at once:
console.log(JSON.stringify(JSON.parse(raw), null, 2));
/* Output:
{
"orderId": 9007199254740992, // WRONG! Silently rounded down by 1
"amount": 49, // Trailing .00 decimal dropped
"role": "admin" // First duplicate key silently vanished!
}
*/
If you copy a formatted payload out of a naive formatter and paste that silently rounded orderId into a database query, refund endpoint, or bug ticket, you are now looking up the wrong customer record without realizing anything changed.
Duplicate Object Keys & Parser Security Desyncs
RFC 8259 states that member names within a JSON object “SHOULD be unique,” yet does not require parsers to reject duplicate keys. As a result, real-world parsers disagree dramatically:
- Last-key-wins: JavaScript
JSON.parse(), Pythonjson.loads(), and Go’sencoding/jsonoverwrite earlier properties with the last occurrence. - First-key-wins: Several legacy C/Java parsers and security WAF rules inspect only the first matching key.
- Rejection: Strict validators fail on duplicates entirely.
When a naive formatter runs JSON.parse(), duplicate keys silently disappear before you ever see them — hiding subtle backend serialization bugs and even JSON parser differential vulnerabilities (where an API gateway authorizes "role": "guest" while the downstream service executes "role": "admin"). A lossless AST formatter preserves every key-value pair in original order and flags duplicate keys explicitly so you catch them immediately.
Why 1.0 vs 1 Matters in Schemas & Diffs
In typed backends (Go, Rust, Java, Protobuf JSON mapping, and OpenAPI validators), 1.0 and 1 are not always interchangeable. Strict schema validators or typed deserializers sometimes distinguish floating-point fields from integer fields, and snapshot tests diff formatted JSON line by line.
Because JSON.parse("1.00") produces the JavaScript number 1, re-serializing strips the decimal suffix completely and normalizes scientific notation (e.g., 1e-7 vs 0.0000001). Keeping the exact numeric source lexeme avoids noisy diffs and preserves financial or scientific precision verbatim.
How a Lossless RFC 8259 Tokenizer & AST Works
Instead of delegating to JavaScript’s native object model, Lasita DevKit JSON Formatter parses your input with a dedicated RFC 8259 tokenizer and Abstract Syntax Tree (AST):
// Lossless RFC 8259 AST node preserves exact source lexemes:
type JsonNumberNode = {
type: 'number';
raw: string; // Exact source text: "9007199254740993" or "49.00"
line: number;
column: number;
};
type JsonObjectNode = {
type: 'object';
entries: Array<{ key: string; value: JsonNode; isDuplicateKey: boolean }>;
}; - Lexical preservation: Numbers are stored as validated raw strings (
"9007199254740993","49.00"), verified strictly against RFC 8259 grammar (no leading zeros like01, no bare.5, noNaNorInfinity). - Ordered entry arrays: Objects store ordered lists of entries rather than plain JS dictionaries, preserving both original key order (even for integer-like string keys such as
"2"before"1", which JavaScript objects reorder automatically!) and duplicate key occurrences. - Line-accurate error recovery & fix previews: Because every token tracks exact 1-based line and column offsets, syntax errors point to the exact offending character — and common mistakes like trailing commas or single quotes can be inspected cleanly before applying a fix.
Inspecting Large API Payloads with Tree View, JSONPath & Web Workers
Formatting a 5 MB or 10 MB API dump on the main browser thread causes noticeable input lag. Moving the RFC 8259 parser and formatter into a dedicated Web Worker inside an isolated cross-origin frame (devkit-frame.lasita.dev with connect-src 'none') solves both speed and security:
- Collapsible Tree View: Collapse noisy arrays and drill straight into deeply nested metadata objects without scrolling through 50,000 lines of raw text.
- JSONPath lookup: Query fields across arrays (for example,
$.items[*].idor$.data.users[0].email) directly in browser memory. - Safe for production payloads: Because the sandbox enforces
connect-src 'none', sensitive customer data, webhook logs, and configuration tokens never leave your machine. Try it live at devkit.lasita.dev/json-formatter.
About the author
Abishek Verma
Software engineer & writer behind Lasita · India
Abishek Verma builds and maintains every Lasita tool and writes each guide on this site. Lasita began as a simple idea: everyday file, developer and date utilities should work entirely inside your browser, so nothing you open in them has to be uploaded to someone else’s server.
Spotted a mistake or have a question about this guide? Email contact@lasita.dev.
More guides
All 8 guides →Privacy & Architecture · 8 min read
Dual-Origin Isolation & WASM Privacy
Developer Utilities · 9 min read
Developer Data & WCAG Reference
Developer Utilities · 8 min read