title: Trying to get a JSON response that includes square brackets from this MySQL PHP code (objects and arrays)
body: <p>php code:</p>
  
  <pre><code>&lt;?php 
  $mysqli = new mysqli("localhost","root","root","thinkorders"); //Database connection start
  $sql = "select * from psv_post"; //fetch table data 
  $result = $mysqli-&gt;query($sql); //process query
  $json_response = array();  //main array 
  $shipping_address_details = array(); 
  $items_details = array();
  while($row=$result-&gt;fetch_array(MYSQLI_BOTH))
  {
      //main array
      $json_response['contact_id']  = $row['contact_id'];
  
      //shipping_address details array 
      $shipping_address_details['country'] = $row['shipping_address_country'];
  
      //items_details array
      $items_details['type'] = $row['items_type'];
  
      //push shipping address into shipping_address details array 
      $json_response['shipping_address'][] = $shipping_address_details;
  
      //push items into items_details array 
      $json_response['items'][] = $items_details;
  
  }
  header('Content-type: text/javascript');
  //echo json_encode($json_response);
  $json_output =  json_encode($json_response); //OUTPUT  
  //remove square braces from json string 
  $json_output = str_replace('[','',$json_output);
  echo $json_output = str_replace(']','',$json_output);
  
  ?&gt;
  </code></pre>
  
  <p>this code returns:</p>
  
  <pre><code>{
    "contact_id": "625",
    "shipping_address": {
      "country": "USA"
    },
    "items": {
      "type": "paper"
    }
  }
  </code></pre>
  
  <p>i need it like this:</p>
  
  <pre><code>{
    "contact_id": "625",
    "shipping_address": {
      "country": "USA"
    },
    "items": [
      {
        "type": "paper"
      }
    ]
  }
  </code></pre>
  
  <p>After searching for a couple of hours it seems that its an array inside an object (see the square brackets), but everything i try has not worked. If someone can see an easy fix, please reply. Thank you!</p>