How to pretty print JSON Object

JSON Object를 화면에 바로 보여주어야 할 때, 그냥 바로 출력을 하면 한줄로 길게 표현이 되기 때문에, 가독성이 떨어진다. 하지만 다음과 같이 하면 들여쓰기를 하여 JSON Object를 보기 좋게 프린트 할 수 있다.

1. Html

<pre><code class=JsonResult></code></pre>

2. Javascript

var jsonObject = [{name: "Gil-Dong", Age: 20, Birthday: new Date("2001-01-01")},{name: "Young-Hee", Age: 25, Birthday: null}];

$('.JsonResult').html(JSON.stringify(jsonObject, null, 3));

3.Result

[
   {
      "name": "Gil-Dong",
      "Age": 20,
      "Birthday": "2001-01-01T00:00:00.000Z"
   },
   {
      "name": "Young-Hee",
      "Age": 25,
      "Birthday": null
   }
]