JSON.rawJSON
Creates a raw JSON object that can be included in a JSON string without being re-serialized
Syntax
JSON.rawJSON(string)Parameters
| Parameter | Type | Description |
|---|---|---|
| string | string | A valid JSON string to be treated as raw JSON |
Return Value
A raw JSON value object that can be used with JSON.stringify
Examples
const raw = JSON.rawJSON('123.456');
console.log(JSON.stringify({ value: raw }));
// '{"value":123.456}'const bigNum = JSON.rawJSON('9007199254740993');
const json = JSON.stringify({ id: bigNum });
console.log(json); // '{"id":9007199254740993}'const raw = JSON.rawJSON('"already a string"');
console.log(JSON.stringify({ msg: raw }));
// '{"msg":"already a string"}'Understanding JSON.rawJSON
The JSON.rawJSON method in JavaScript creates a raw JSON object that can be included in a JSON string without being re-serialized. It belongs to the JSON object and is one of the most widely used methods for working with json values in modern JavaScript and TypeScript applications.
The method signature is JSON.rawJSON(string). It accepts 1 parameter: string. When called, it returns a raw json value object that can be used with json.stringify. Understanding when and how to use rawJSON() helps you write more expressive, readable code.
Common use cases for JSON.rawJSON include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like json-israwjson, json-parse, json-stringify, enabling you to chain operations together for complex data manipulation pipelines.
Supported in Chrome 114+, Firefox 135+, and Node.js 22+. Safari support is pending.
Browser Compatibility
Supported in Chrome 114+, Firefox 135+, and Node.js 22+. Safari support is pending.
Related Methods
JSON.isRawJSONDetermines whether a value is an object returned by JSON.rawJSON
JSON.parseParses a JSON string, constructing the JavaScript value or object described by the string
JSON.stringifyConverts a JavaScript value to a JSON string, optionally replacing values or including only specified properties
More JSON Methods
Other methods in the JSON object
Related Tools
More JSON Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.