TL;DR: JSON.parse now hands your reviver the original text of every primitive, and JSON.rawJSON() lets JSON.stringify write numbers back out exactly. Big IDs survive the round trip, no third-party parser needed.

Two orders walk into a parser

Your API returns two orders. They have different IDs. JavaScript disagrees:

const body = `{ "orders": [ { "id": 1859162453872926720, "total": 19.90, "items": 3 }, { "id": 1859162453872926721, "total": 5.00, "items": 1 } ] }`; const naive = JSON.parse(body); console.log(naive.orders.map(o => o.id)); // [ 1859162453872926700, 1859162453872926700 ] console.log(naive.orders[0].id === naive.orders[1].id); // true 

Two different orders, one ID. That is not a display bug. JSON numbers become JavaScript Numbers, and a Number holds integers exactly only up to Number.MAX_SAFE_INTEGER, which is 9007199254740991. Anything past that gets rounded to the nearest double before your code ever sees it.

The usual fixes all hurt a bit. Ask the backend to send IDs as strings. Pull in a custom JSON parser. Or regex the response text before parsing, which works right up until it does not.

What changed

The reviver callback of JSON.parse gets a third argument, context. For primitive values, context.source is the exact JSON text the value came from. The rounding still happens, but now you can look past it.

The other half is JSON.rawJSON(text). It returns a frozen, null-prototype object that JSON.stringify writes out verbatim, with no quotes added. So you can produce a number token too big for Number.

The proposal is "JSON.parse source text access", and it is at stage 4 in TC39, listed for ES2026.

The minimal version

const text = '{"id": 12345678901234567890, "name": "order"}'; console.log(JSON.parse(text).id); // 12345678901234567000 const data = JSON.parse(text, (key, value, context) => { if (key === "id") return BigInt(context.source); return value; }); console.log(data.id, typeof data.id); // 12345678901234567890n bigint 

The reviver still receives the rounded value. It just also receives the receipt.

The realistic version

Hard-coding key names gets old fast. A better rule: if the parsed number is an integer that is no longer safe, and the source is an integer literal, use BigInt. Everything else stays a normal number.

function revive(key, value, { source } = {}) { if ( typeof value === "number" && !Number.isSafeInteger(value) && /^-?\d+$/.test(source) ) { return BigInt(source); } return value; } function replace(key, value) { return typeof value === "bigint" ? JSON.rawJSON(value.toString()) : value; } const { orders } = JSON.parse(body, revive); console.log(orders.map(o => o.id)); // [ 1859162453872926720n, 1859162453872926721n ] console.log(orders[0].id === orders[1].id); // false console.log(orders.map(o => o.total), orders.map(o => o.items)); // [ 19.9, 5 ] [ 3, 1 ] console.log(JSON.stringify({ ids: orders.map(o => o.id) }, replace)); // {"ids":[1859162453872926720,1859162453872926721]} 

Totals and item counts stay plain numbers, so nothing else in your code has to learn about BigInt. The IDs come back as BigInt, and the replacer sends them out as bare JSON numbers, digit for digit. The = {} default keeps revive from crashing in an engine that passes no context; there it simply returns the rounded value.

A value like 1e21 is not safe either, but its source is not an integer literal, so it stays a Number. The regex is doing real work there.

Can I use it?

Yes. JSON source text access is Baseline Newly available since March 2025:

Browser First version
Chrome and Edge 114
Firefox 135
Safari (macOS and iOS) 18.4

It is also in Node.js, which is where every snippet in this post was run (Node 24.11.0). Baseline Widely available is expected in October 2027, so keep an eye on older Safari if your users skip updates.

Gotchas

1. context.source exists only for primitives. For an object or an array, context is an empty object. When you log context for every key of {"a": 1.0, "c": [1], "d": {"e": true}}, "a" gets {"source":"1.0"} while "c" and "d" get {}. Check source before you use it.

2. source is the raw text, not a normalized value. 1.0 arrives as "1.0", 1e3 as "1e3", and a string as "\"x\"", quotes included. That is the point, but it means BigInt(context.source) throws on anything that is not an integer literal.

3. JSON.rawJSON takes one primitive, exactly. JSON.rawJSON('{"a":1}') and JSON.rawJSON("[1]") throw a SyntaxError, and so do " 1", "1 " and "". It is a way to write one token, not a way to sneak in a whole subtree. What you pass is what you get: JSON.rawJSON("1.0") stringifies as 1.0, not 1.

4. JSON.stringify still refuses a bare BigInt. Parsing into BigInt is only half the trip. Without a replacer, the way back fails just like before:

JSON.stringify({ id: 12345678901234567890n }); // TypeError: Do not know how to serialize a BigInt JSON.stringify({ id: 12345678901234567890n }, (k, v) => typeof v === "bigint" ? JSON.rawJSON(v.toString()) : v); // {"id":12345678901234567890} 

Wrap-up

If your app talks to an API with 64-bit IDs, find the one place you call JSON.parse on its responses and give it a reviver. Your orders will thank you for keeping them apart.

Sources

This article was written with the help of AI and checked against the sources above.