title: How to output JSON data correctly using PHP
body: <p>I'm developing an Android app, and for the API I'm sending my requests to a URL that should return JSON data.</p>
  
  <p>This is what I'm getting in my output:
  <img src="https://i.stack.imgur.com/F74Rr.png" alt="My response"></p>
  
  <p>And I'd like it to be displayed as Twitter response:</p>
  
  <p><img src="https://i.stack.imgur.com/KUW2o.png" alt="Twitter&#39;s JSON response"></p>
  
  <p>I'm assuming my response is not being parsed by the JSON Formatter Chrome extension because it's encoded badly, thus my app can't get the values I need.</p>
  
  <p>Here's my PHP code:</p>
  
  <pre><code>&lt;?php
  
  $response = array();
  
  if (isset($_POST['name']) &amp;&amp; isset($_POST['price']) &amp;&amp; isset($_POST['description'])) 
  {
  
      $name = $_POST['name'];
      $price = $_POST['price'];
      $description = $_POST['decription'];
  
      require_once __DIR__ . '/db_connect.php';
  
      $db = new DB_CONNECT();
  
      $result = mysql_query("INSER INTO products(name, price, description) VALUES('$name', '$price', '$description')");
  
      if ($result) {
          $response["success"] = 1;
          $response["message"] = "Product successfully created.";
  
          echo json_encode($response);
      } else {
  
          $response["success"] = 0;
          $response["message"] = "Oops! An error occurred!";
  
          echo json_encode($response);
          }
  } else {
  
      $response["success"] = 0;
      $response["message"] = "Required field(s) is missing";
  
      echo json_encode($response);
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>I want to know how to display the JSON data correctly so that JSON Formatter and my android App can parse it correctly.</p>