title: Adding json object to test.json file in php
body: <p>I have a json file test.json which has following structure in it </p>
  
  <pre><code>{
      "test": {
          "parts": [
               {
                  "partgroup": "1",
                  "screens": [
                      {
                          "questions": [
                              {
                                  "questionno": 1
                              }
                          ]
                      }
                  ]
              }
          ]
      }
  }
  </code></pre>
  
  <p>I need to add a partgroup inside that parts array my workaround looks like this</p>
  
  <pre><code>$data[] = '{
                  "partgroup": "2",
                  "screens": [
                      {
                          "questions": [
                              {
                                  "questionno": 1
                              }
                          ]
                      }
                  ]
              }';
  $json = file_get_contents("test.json", FILE_USE_INCLUDE_PATH);
   foreach($json['test'] as $key=&gt;$value):
       $tempArray = $value['parts'];
   endforeach;
  array_push($tempArray, $data);
  $jsonData = json_encode($tempArray);
  file_put_contents('test.json', $jsonData);
  </code></pre>
  
  <p>here the output is just appending the json at end of the test.json file.
  can anyone help me to put the data inside the parts section in the JSON file?</p>