In JavaScript, JSON.rawJSON() takes a string that is already valid JSON and wraps it as a special βrawβ value. When you later call JSON.stringify(), that raw value is pasted into the output as-is.
This avoids double-encoding. A normal string becomes "..." with quotes and escapes. A raw JSON value is treated as ready-made JSON text: a number, object, array, and so on. Check values with JSON.isRawJSON().
Syntax
Pass a complete JSON text string. Then put the result where you would put any other value before stringifying.
Wraps the number text 42 so stringify writes a bare number.
JSON.rawJSON('{"ok":true}')
Wraps a small object so it is nested without being turned into a quoted string.
The argument must be a full JSON value. Partial fragments like "a":1 without braces are invalid.
Library declarations
JavaScript
// ECMAScript 2024 (ES2024)
JSON.rawJSON(text)
// text : a string that is valid JSON text
// returns : a raw JSON value for use with JSON.stringify()
// throws : SyntaxError when text is not valid JSON
Parameters
Parameter
Description
text
Required. A string of valid JSON: a number, string, boolean, null, object, or array.
Return Value
Return Value
Description
Raw JSON value
A special object that JSON.stringify() embeds as the original text.
SyntaxError (thrown)
Thrown when text is not valid JSON.
JavaScript Examples
Example 1 — Embed a Number as Raw JSON
Write a large number as bare JSON text instead of a quoted string.
JavaScript
if (typeof JSON.rawJSON !== "function") {
console.log("JSON.rawJSON is not supported here.");
} else {
const data = {
id: JSON.rawJSON("9007199254740993")
};
console.log(JSON.stringify(data));
}
JSON.rawJSON() is part of ES2024. Support is growing. Check before you use it in production, or feature-detect with typeof JSON.rawJSON === "function".
✓ ES2024 · Newer API
JSON.rawJSON()
Available in recent Chrome, Edge, Firefox, Safari, and Node.js versions that implement JSON raw values. Older engines do not have it.
ES2024Standard since
Google Chrome114+ · Desktop & Mobile
Full support
Microsoft Edge114+ · Chromium
Full support
Mozilla Firefox126+ · Desktop & Mobile
Full support
Apple Safari17.4+ · macOS & iOS
Full support
Opera100+ · Chromium based
Full support
Samsung InternetRecent versions · Android
Varies
Android WebView114+ · Chromium based
Supported
Node.js21+ · Server runtime
Supported
DenoRecent versions · JavaScript runtime
Supported
BunRecent versions · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
JSON.rawJSON()Growing
Bottom line: Feature-detect before use. For everyday parse and stringify needs, JSON.parse() and JSON.stringify() are enough.
Frequently Asked Questions
It takes a string that is already valid JSON and wraps it as a special raw value. When JSON.stringify() sees that value, it pastes the text as-is instead of turning it into a quoted string again.
Use it when you already have a JSON fragment as text and you want to nest it inside a larger object without double-encoding. It is also useful for values that stringify cannot write by itself, such as a BigInt written as a number.
A raw JSON object. You do not read it like a normal object. Pass it to JSON.stringify(), or check it with JSON.isRawJSON().
JSON.rawJSON() throws a SyntaxError. The text must be a complete JSON value: a number, string, boolean, null, object, or array.
No. It is a newer method (ES2024). Check support in your browser or Node.js version, or use JSON.isRawJSON to detect the feature at runtime.
A normal string becomes a quoted JSON string with escapes. A raw JSON value is inserted as raw text, so 9007199254740993n can appear as a bare number in the output.