Get to know MDN better
Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The JSON.rawJSON() static method creates a "raw JSON" object containing a piece of JSON text. When serialized to JSON, the raw JSON object is treated as if it is already a piece of JSON. This text is required to be valid JSON.
The JSON text. Must be valid JSON representing a primitive value.
An object that can be used to create JSON text with the exact same content as the string provided, without quotes around the string itself. This object has null prototype and is frozen (so it never gets accidentally serialized as a regular object by any kind of primitive conversion), and the following property:
rawJSONThe original JSON string provided.
Furthermore, it has a private field that marks itself as a raw JSON object. This allows it to be identified by JSON.stringify() and JSON.isRawJSON().
Thrown if the string is not valid JSON, or if it represents an object or array.
A raw JSON object can be seen as an immutable, atomic data structure like any kind of primitive. It is not a regular object and it contains no data other than the raw JSON text. It is used to "pre-serialize" data to formats that JSON.stringify itself cannot produce for various reasons. The most typical use case is the floating point number loss of precision problem. For example:
The value is not exactly equivalent to the original number any more! This is because JavaScript uses floating point representation for all numbers, so it cannot represent all integers exactly. The number literal 12345678901234567890 itself is already rounded to the nearest representable number when it is parsed by JavaScript.
Without JSON.rawJSON, there is no way to tell JSON.stringify to produce the number literal 12345678901234567890, because there is simply no corresponding JavaScript number value. With raw JSON, you can directly tell JSON.stringify() what a particular value should be stringified as:
For a more complete example of this, see Lossless number serialization.
Note that although we passed a string to JSON.rawJSON(), it still becomes a number in the final JSON. This is because the string represents the verbatim JSON text. If you want to serialize a string, you should use JSON.rawJSON() with a quotes-enclosed string value:
JSON.rawJSON allows you to insert arbitrary JSON text, but does not allow you to create invalid JSON. Anything that was not permitted by the JSON syntax is not permitted by JSON.rawJSON() either:
Furthermore, you cannot use JSON.rawJSON() to create JSON objects or arrays.
However, you cannot use JSON.rawJSON() to create JSON objects or arrays:
Apart from numbers, there is only one other type that does not have a one-to-one correspondence between JavaScript values and JSON text: strings. When strings are serialized to JSON, all code points, other than those that are not legal inside JSON string literals (such as line breaks), are printed literally:
This may not be desirable, because the receiver of this string may handle Unicode differently. To improve interoperability, you can explicitly specify the string to be serialized with escape sequences:
Note that the double backslashes in the rawJSON actually represents a single slash character.
| JSON.parse source text access # sec-json.rawjson |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.