title: PHP "pretty print" json_encode
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6054033/pretty-printing-json-with-php">Pretty-Printing JSON with PHP</a>  </p>
  </blockquote>
  
  
  
  <p>I'm working on a script that creates a JSON file. Right now I'm just using <code>json_encode</code> (PHP 5.2.x) to encode an array into JSON output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability, so I'd like to add line breaks in and "pretty print" the JSON output. Any ideas on how to do this? My only other alternative that I can see is to not use <code>json_encode</code> at all and just write the file contents manually and add in my own line breaks for each line.</p>
  
  <p>Here's what I get:</p>
  
  <pre><code>{"product_name":"prod1","val1":1,"val2":8}
  </code></pre>
  
  <p>Here's what I want:</p>
  
  <pre><code>{
    "product_name":"prod1",
    "val1":1,
    "val2":8
  }
  </code></pre>
  
  <p>I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?</p>