title: Unable to format json data in php
body: <p>I am working on retrofit. I am fetching data from online server using <strong>php</strong>, but my <strong>json</strong> is not formatted correctly. So many people have asked this question but no one answer is working for me.</p>
  
  <p>Here is my php code</p>
  
  <pre class="lang-php prettyprint-override"><code>    &lt;?php
      header("Content-type:application/json");
  
      require_once('connect.php');
  
      $query = mysqli_query($conn,"SELECT * FROM `retrofit` ") ;
  
      $response = array();
  
      while($row = mysqli_fetch_assoc($query)){
  
          array_push($response,
          array(
              'userId' =&gt;$row['userId'],
              'id' =&gt;$row['id'],
              'title' =&gt;$row['title'],
              'body' =&gt;$row['body']));
      }
  
      echo json_encode($response);
  
  ?&gt;
  </code></pre>
  
  <p>And here is the output:</p>
  
  <blockquote>
    <p>[{"userId":"1","id":null,"title":"sunt aut facere repellat provident occaecati excepturi optio reprehenderit","body":"quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"},{"userId":"1","id":null,"title":"qui est esse","body":"est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"}]</p>
  </blockquote>