JavaScript JSON isRawJSON()
Syntax & Examples

isRawJSON() static-method

The JSON.isRawJSON() method tests whether a given value is an object returned by JSON.rawJSON(). This method is useful for identifying raw JSON objects.


Syntax of isRawJSON()

The syntax of JSON.isRawJSON() static-method is:

JSON.isRawJSON(value)

This isRawJSON() static-method of JSON tests whether a value is an object returned by JSON.rawJSON().

Parameters

ParameterOptional/RequiredDescription
valuerequiredThe value to be tested if it is an object returned by JSON.rawJSON().

Return Type

JSON.isRawJSON() returns value of type Boolean.



✐ Examples

1 Testing a raw JSON object

In JavaScript, we can use the JSON.isRawJSON() method to check if a given value is a raw JSON object.

For example,

  1. We define a variable raw using JSON.rawJSON() method.
  2. We use the JSON.isRawJSON() method to test if raw is a raw JSON object.
  3. The result is stored in the variable isRaw.
  4. We log isRaw to the console using console.log() method.

JavaScript Program

const raw = JSON.rawJSON({ key: 'value' });
const isRaw = JSON.isRawJSON(raw);
console.log(isRaw);

Output

true

2 Testing a regular object

In JavaScript, we can use the JSON.isRawJSON() method to check if a given value is not a raw JSON object.

For example,

  1. We define a regular JavaScript object obj with a key-value pair.
  2. We use the JSON.isRawJSON() method to test if obj is a raw JSON object.
  3. The result is stored in the variable isRaw.
  4. We log isRaw to the console using console.log() method.

JavaScript Program

const obj = { key: 'value' };
const isRaw = JSON.isRawJSON(obj);
console.log(isRaw);

Output

false

3 Testing a string value

In JavaScript, we can use the JSON.isRawJSON() method to check if a string value is a raw JSON object.

For example,

  1. We define a string variable str with a value.
  2. We use the JSON.isRawJSON() method to test if str is a raw JSON object.
  3. The result is stored in the variable isRaw.
  4. We log isRaw to the console using console.log() method.

JavaScript Program

const str = 'Hello, World!';
const isRaw = JSON.isRawJSON(str);
console.log(isRaw);

Output

false

Summary

In this JavaScript tutorial, we learned about isRawJSON() static-method of JSON: the syntax and few working examples with output and detailed explanation for each example.