title: How to output a properly formatted JSON from a PHP file?
body: <p>I have this code:</p>
  
  <pre><code>&lt;?php
  
      header('Content-Type: text/javascript; charset=UTF-8');
      header('Cache-Control: private, no-cache, no-store, must-revalidate');
      header('Pragma: no-cache');
      header('Expires: Sat, 01 Jan 2000 00:00:00 GMT');
  
      $data = array(
          "data" =&gt; array(
              "sender" =&gt; "Jhon Andrew",
              "recipient" =&gt; "Someone OverThe Internet",
              "conversation" =&gt;
              array(
                  "unix" =&gt; "1234567890",
                  "message" =&gt; "Lorem ipsum dolor sit amet."
              ),
              array(
                  "unix" =&gt; "0987654321",
                  "message" =&gt; "Tema tis rolod muspi merol."
              )
          )
      );
  
      echo json_encode($data);
  
  ?&gt;
  </code></pre>
  
  <p>And I was expecting this kind of result:</p>
  
  <pre><code>{
      "data": {
          "sender":"Jhon Andrew",
          "recipient":"Someone OverThe Internet",
          "message":"Lorem ipsum dolor sit amet."
      }
  }
  </code></pre>
  
  <p>But I got it displayed in just one line, like this:</p>
  
  <pre><code>{"data":{"sender":"Jhon Andrew","recipient":"Someone OverThe Internet","message":"Lorem ipsum dolor sit amet."}}
  </code></pre>
  
  <p>How can I get properly formatted JSON output just like what I am expecting? It's not really important actually, but I just want to see the result in good format.</p>
  
  <hr>
  
  <blockquote>
    <p>...by the way, I just copied the headers from facebooks graph link
    because that is how I want to output the result. Example:
    graph.facebook.com/mOngsAng.gA</p>
  </blockquote>
  
  <hr>
  
  <blockquote>
    <p>It is valid of course. All I want to know is how to output it like
    this: graph.facebook.com/mOngsAng.gA - As you can see it is properly
    formatted. I mean it has line breaks and indentions. Unlike what I am
    getting is just showed in one line.</p>
  </blockquote>