JavaScript JSON.isRawJSON() Method

Beginner
4 min read
Updated: Nov 2026
3 examples
JSON

Definition

In JavaScript, JSON.isRawJSON() answers one question: was this value made with JSON.rawJSON()? It returns true or false.

Use it in helpers that accept mixed data. If the value is raw, pass it to JSON.stringify() as-is. If it is not, treat it as a normal value. Learn how to create raw values on the JSON.rawJSON() page.

Syntax

Pass any value. The method only returns true for raw JSON values.

JavaScript
JSON.isRawJSON(value);

JSON.isRawJSON(JSON.rawJSON("1"));  // true
JSON.isRawJSON("1");                // false
CallWhat it does
JSON.isRawJSON(raw)Returns true when raw came from JSON.rawJSON().
JSON.isRawJSON(other)Returns false for strings, numbers, objects, arrays, null, and everything else.

Feature-detect first: typeof JSON.isRawJSON === "function".

Library declarations
JavaScript
// ECMAScript 2024 (ES2024)
JSON.isRawJSON(value)

// value   : any JavaScript value
// returns : true if value is a raw JSON value, otherwise false

Parameters

ParameterDescription
valueRequired. Any value you want to test.

Return Value

Return ValueDescription
trueThe value was created with JSON.rawJSON().
falseThe value is not a raw JSON value.

JavaScript Examples

Example 1 — Basic JSON.isRawJSON()

Compare a raw value with a normal string.

JavaScript
if (typeof JSON.isRawJSON !== "function") {
  console.log("JSON.isRawJSON is not supported here.");
} else {
  const raw = JSON.rawJSON("42");
  const text = "42";

  console.log(JSON.isRawJSON(raw));
  console.log(JSON.isRawJSON(text));
}
Try It Yourself

How It Works

  1. JSON.rawJSON("42") builds a raw value.
  2. isRawJSON returns true for that value.
  3. The plain string "42" returns false.

Example 2 — Other Types Are False

Numbers, objects, arrays, and null are not raw JSON values.

JavaScript
if (typeof JSON.isRawJSON !== "function") {
  console.log("JSON.isRawJSON is not supported here.");
} else {
  console.log(JSON.isRawJSON(42));
  console.log(JSON.isRawJSON({ a: 1 }));
  console.log(JSON.isRawJSON([1, 2]));
  console.log(JSON.isRawJSON(null));
  console.log(JSON.isRawJSON(undefined));
  console.log(JSON.isRawJSON(JSON.rawJSON("null")));
}
Try It Yourself

How It Works

  1. Everyday values all return false.
  2. Only the last call wraps null with rawJSON.
  3. That wrapped value returns true.

Example 3 — A Small Helper

Build a payload that accepts either a raw value or a normal object.

JavaScript
if (typeof JSON.isRawJSON !== "function") {
  console.log("JSON.isRawJSON is not supported here.");
} else {
  function wrapBody(body) {
    if (JSON.isRawJSON(body)) {
      return { body: body };
    }
    return { body: body };
  }

  const fromText = JSON.rawJSON('{"ok":true}');
  const fromObject = { ok: true };

  console.log(JSON.stringify(wrapBody(fromText)));
  console.log(JSON.stringify(wrapBody(fromObject)));
  console.log("First body is raw: " + JSON.isRawJSON(fromText));
  console.log("Second body is raw: " + JSON.isRawJSON(fromObject));
}
Try It Yourself

How It Works

  1. Both payloads stringify to the same shape.
  2. isRawJSON still tells them apart before stringify.
  3. Use that check when a helper must handle both kinds of input.

Browser & Runtime Support

JSON.isRawJSON() is part of ES2024, together with JSON.rawJSON(). Feature-detect before use.

✓ ES2024 · Newer API

JSON.isRawJSON()

Available in recent Chrome, Edge, Firefox, Safari, and Node.js versions that implement JSON raw values. Older engines do not have it.

ES2024 Standard since
Google Chrome 114+ · Desktop & Mobile
Full support
Microsoft Edge 114+ · Chromium
Full support
Mozilla Firefox 126+ · Desktop & Mobile
Full support
Apple Safari 17.4+ · macOS & iOS
Full support
Opera 100+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Varies
Android WebView 114+ · Chromium based
Supported
Node.js 21+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
JSON.isRawJSON() Growing

Bottom line: Feature-detect both JSON.isRawJSON and JSON.rawJSON. For everyday work, JSON.parse() and JSON.stringify() are enough.

Frequently Asked Questions

It returns true when the value was created with JSON.rawJSON(), and false for every other value: strings, numbers, objects, null, and so on.
Helpers and libraries can treat raw values differently: pass them through to stringify, or reject them if the API expects a normal object. The check keeps that logic clear.
Always a boolean: true or false. It does not throw for normal inputs.
No. Only values created by JSON.rawJSON() are raw. A look-alike object still returns false.
No. It arrives with JSON.rawJSON() in ES2024. Feature-detect both methods before you use them.
Use typeof JSON.isRawJSON === "function". If the method is missing, skip raw-JSON paths and use normal stringify instead.

Back to JSON Methods

See the full index of JavaScript JSON method tutorials.

JSON methods index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful