이 util.inspect()
을 사용하여 달성 될 것으로 보인다 :
const util = require('util');
const testJson = `{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}`
x = JSON.parse(testJson);
x.x = x;
console.log(util.inspect(x, { colors: true }));

옵션은 오브젝트는 재귀 얼마나 깊은 결정 depth
라는 매개 변수를 사용합니다.
console.log(util.inspect(x, { colors: true, depth: 3 }));
나는 다음과 같은 얻을 :

그것이 depth: null
을 통과 무한 재귀하려면 내가 3으로 증가하는 경우 기본값은 2입니다. 노드 cli에서도 기본값이 2 인 것처럼 보입니다.