JSON.isRawJSON()
Baseline
2025
Newly available
Since March 2025, 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.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> |