title: Javascript: How to generate formatted easy-to-read JSON straight from an object?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2614862/how-can-i-beautify-json-programmatically">How can I beautify JSON programmatically?</a>  </p>
  </blockquote>
  
  
  
  <p>I know how to generate JSON from an object using JSON.stringify, or in my case the handy jquery-json from google code (<a href="https://github.com/krinkle/jquery-json" rel="noreferrer">https://github.com/krinkle/jquery-json</a>).  </p>
  
  <p>Now this works fine, but the output is hard to read for humans.  Is there an easy way / function / whatever to output a neatly formatted json file?</p>
  
  <p>This is what I mean:</p>
  
  <pre><code>JSON.stringify({a:1,b:2,c:{d:1,e:[1,2]}}); 
  </code></pre>
  
  <p>gives..</p>
  
  <pre><code>"{"a":1,"b":2,"c":{"d":1,"e":[1,2]}}"
  </code></pre>
  
  <p>I'd like something like this instead:</p>
  
  <pre><code>{
   "a":1,
   "b":2,
   "c":{
      "d":1,
      "e":[1,2]
   }
  }
  </code></pre>
  
  <p>E.g. with newlines and tabs added. It's much easier to read for larger documents.</p>
  
  <p>I'd like to do this ideally without adding any huge libraries - e.g. not prototype or YUI or whatever.  </p>