← Back to News
JSON

JSON.parse Source Access and JSON.rawJSON Reach the Modern Web

JSON.parse Source Access and JSON.rawJSON Reach the Modern Web

What Reached the Web Platform?

The long-running TC39 work on source-aware JSON parsing is now reflected in both the ECMAScript specification and current browser-facing documentation. The update adds a third argument to JSON.parse() revivers so primitive values can expose their original source text through context.source, and it adds JSON.rawJSON()for lossless serialization of primitive JSON text.

That matters because classic JSON.parse() and JSON.stringify()have always been lossy at the edges. Large integers can round before application code sees them, and JavaScript has had no standards-based way to tell JSON.stringify()to emit an exact numeric literal that cannot be represented as a normal Number.

Why This Matters for JSON Tools

For browser-based developer tools, this is a meaningful quality-of-implementation change. A local-first JSON utility can preserve the exact token text for primitive values during parsing, which is useful when debugging API payloads containing long numeric IDs, financial values, hashes, or other precision-sensitive fields.

On the serialization side, JSON.rawJSON() lets tooling emit exact primitive JSON text instead of relying on JavaScript number coercion. That makes standards-compliant browser tooling more credible for lossless inspection, transformation, and round-tripping workflows that previously needed custom serializers or server-side helpers.

How Developers Can Use It

The new reviver context is most useful when you need the original lexical form of a primitive after parsing. A tool can inspect context.source to distinguish between a large integer that was rounded into a JavaScript Number and the original digits that appeared in the payload.

JSON.rawJSON() is the inverse for output. Instead of serializing a rounded number and then explaining the discrepancy to the user, a tool can explicitly preserve a primitive JSON token when constructing output. The API still enforces valid JSON and does not allow arbitrary object or array injection, which keeps it aligned with standards-based JSON generation instead of turning into a string-concatenation escape hatch.

Compatibility and Fallbacks

MDN marks JSON.rawJSON() as a Baseline 2025 feature and notes that it has worked across the latest browsers since March 2025, with the usual caveat that older devices may lag. That means browser-first tools can start using these APIs selectively, but should still feature-detect them before depending on lossless behavior.

The practical pattern is straightforward: use the newer APIs when they exist, and fall back to older parse-and-stringify behavior when they do not. For a privacy-conscious site such as fixjson.org, that keeps more precision-sensitive debugging inside the browser tab without sending payloads to a backend just to preserve exact JSON tokens.

Sources

Related on fixjson.org