title: Get data from JSON file in php
body: <p>I am trying to get data from json file , parse it and add data from it to database. I am using as database, oracle.
  I am getting the errors :</p>
  
  <p><a href="https://i.stack.imgur.com/EqJvC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EqJvC.jpg" alt="enter image description here"></a></p>
  
  <p><strong>This is my JSON file</strong></p>
  
  <pre><code>{
  "data": {
      "gps": [
          { "location": "45.778123,24.151165"     
          },
          { "location": "45.7875116,24.1549801"               
          }
      ]
  }
  </code></pre>
  
  <p><strong>This is my php file</strong></p>
  
  <pre><code>    &lt;?php
          $file = 'JSONdata.json';
          $json = file_get_contents($file,0,null,null);
          $obj = json_decode($json,true);
          $data = $obj-&gt;data-&gt;gps;
  
          include 'connection.php';
  
         function insert_data($connname, $conn)
         {
            foreach ($data as $post) {
               $stmt = oci_parse($conn, "insert into GPSLOGS
                     values('".$post-&gt;location."')");
              oci_execute($stmt, OCI_DEFAULT);
              echo "$connname inserted row without committing&lt;br&gt;\n";
              }
         }
  
          insert_data('c1', $conn);
     ?&gt;
  </code></pre>
  
  <p>Do you know what am I doing wrong? And why it keeps getting those errors?
  I also tried using another format of JSON file and parse it differently , but it keeps getting the same errors.</p>
  
  <pre><code>.json
        [{ "gps": "45.778123,24.151165"},{"gps": "45.7875116,24.1549801"}]
  
   .php
       $file = 'JSONdata.json';
       $json = file_get_contents($file,0,null,null);
       $obj = json_decode($json,true);    
         foreach($obj as $item)
         {      echo $item['gps'];}  
  </code></pre>