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
Parameter | Optional/Required | Description |
---|---|---|
value | required | The 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,
- We define a variable
raw
usingJSON.rawJSON()
method. - We use the
JSON.isRawJSON()
method to test ifraw
is a raw JSON object. - The result is stored in the variable
isRaw
. - We log
isRaw
to the console usingconsole.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,
- We define a regular JavaScript object
obj
with a key-value pair. - We use the
JSON.isRawJSON()
method to test ifobj
is a raw JSON object. - The result is stored in the variable
isRaw
. - We log
isRaw
to the console usingconsole.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,
- We define a string variable
str
with a value. - We use the
JSON.isRawJSON()
method to test ifstr
is a raw JSON object. - The result is stored in the variable
isRaw
. - We log
isRaw
to the console usingconsole.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.