title: Append array data as objects to json file
body: <p>I have a simple json file that has a direct image link and the folder name per json object:</p>
  
  <pre><code>[
          {
                  "image": "http://placehold.it/350x150",
                  "folder": "Small"
          },
          {
                  "image": "http://placehold.it/450x250",
                  "folder": "Medium"
          },
          {
                  "image": "http://placehold.it/550x350",
                  "folder": "Medium"
          }
  ]
  </code></pre>
  
  <p>I would like to append those two values from a post, but the result is an unchanged json file. Here is the PHP code w/ comments:</p>
  
  <pre><code>$directLink = $_POST['txtDirectLink'];
  $category = $_POST['selectCategoriesImages'];
  $util-&gt;addToJsonImageList($directLink, $category);
  
  //decodes the json image list, merges to the decoded array a new image, then encodes back to a json file
  function addToJsonImageList($link, $category) {
      $file = file_get_contents('./images_list.json', true);
      $data = json_decode($file);
      unset($file);
  
      $newImage = array('image' =&gt; $link, 'folder' =&gt; $category);
      //$newImage['image'] = $link;
      //$newImage['folder'] = $category;
      $result = array_merge((array)$data, (array)$newImage);
  
      json_encode($result);
      file_put_contents('./images_list.json', $result);
      unset($result);
  }
  </code></pre>
  
  <p>The logic is that it should be simple to json_decode the file as an array, merge the new array onto that, then encode the result and put into the same file. I've been unable to capture any sort of errors either.</p>