| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/JSON/isRawJSON | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
Since 2025 3, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
JSON.isRawJSON() JSON.rawJSON() .
JSON.isRawJSON(value)
value.
value JSON.rawJSON() true, false .
"Raw JSON" JSON JSON . JSON.rawJSON() Raw JSON JSON . Raw JSON JSON.rawJSON() . Raw JSON JSON.stringify() .
JSON.isRawJSON() JSON.rawJSON() . YAML .
function mySerializer(value, indent = "") {
if (typeof value !== "object" || value === null) {
return JSON.stringify(value);
}
if (JSON.isRawJSON(value)) {
return value.rawJSON;
}
const subIndent = `${indent} `;
if (Array.isArray(value)) {
return `- ${value.map((v) => mySerializer(v, subIndent)).join(`\n${indent}- `)}`;
}
return Object.entries(value)
.map(([key, value]) => {
const subValue = mySerializer(value, subIndent);
if (subValue.includes("\n")) {
return `${key}:\n${subIndent}${subValue}`;
}
return `${key}: ${subValue}`;
})
.join(`\n${indent}`);
}
console.log(
mySerializer({
name: "Josh",
userId: JSON.rawJSON("12345678901234567890"),
friends: [
{ name: "Alice", userId: JSON.rawJSON("9876543210987654321") },
{ name: "Bob", userId: JSON.rawJSON("56789012345678901234") },
],
}),
);
// name: "Josh"
// userId: 12345678901234567890
// friends:
// - name: "Alice"
// userId: 9876543210987654321
// - name: "Bob"
// userId: 56789012345678901234
userId JSON.rawJSON() , JS .
console.log(
mySerializer({
name: "Josh",
userId: 12345678901234567890,
friends: [
{ name: "Alice", userId: 9876543210987654321 },
{ name: "Bob", userId: 56789012345678901234 },
],
}),
);
// name: "Josh"
// userId: 12345678901234567000
// friends:
// - name: "Alice"
// userId: 9876543210987655000
// - name: "Bob"
// userId: 56789012345678900000
| Specification |
|---|
| JSON.parse source text access # sec-json.israwjson |
This page was last modified on 2025 1 3 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |