title: Edit a Json File
body: <p>I am trying to use a jQuery gantt as a wordpress plugin. Currently I'm stuck on editing the data.json. I use a php form to populate a new item. When submitting the form, it will add data to the file, but behind the closing square brackets.</p>
  
  <pre><code>[{
    ...
  
   },
   {  "name"  : "Vermessung"
    , "desc"  : ""
    , "values": [
     {  "id"         : "5"
     , "from"       : "/Date(1363132800000)/"
     , "to"         : "/Date(1368655200000)/"
     , "desc"       : "Vom Beauftragen der Vermessung bis zur tatsÃ¤chlichen Vermessung"
     , "customClass": "ganttBlue"
     , "label"      : "Vermessung"
    }
    ]
   }
  ]
  </code></pre>
  
  <p>After submitting the form it looks like this:</p>
  
  <pre><code>[{
    ...
  
   },
   {  "name"  : "Vermessung"
    , "desc"  : ""
    , "values": [
        {  "id"         : "5"
         , "from"       : "/Date(1363132800000)/"
         , "to"         : "/Date(1368655200000)/"
         , "desc"       : "Vom Beauftragen der Vermessung bis zur tatsÃ¤chlichen Vermessung"
         , "customClass": "ganttBlue"
         , "label"      : "Vermessung"
        }
    ]
   }
  ]{"name":null,"desc":null,"values":{"id":null,"from":null,"to":null,"desc":null,"customClass":null,"label":null}}
  </code></pre>
  
  <p>This is the requested php Code which will adding stuff to the json:</p>
  
  <pre><code>$file = jQg_BASENAME_DIR.'/inc/data.json';
  log_me('This is a message for debugging purposes');
  
  if(isset($_POST['submit'])){
  
  $json = file_get_contents( $file );
  $data = json_decode($json);
  
  // convert form data to json format
      $postArray = array(
        "name" =&gt; $_POST['name'],
        "desc" =&gt; $_POST['desc'],
        "values" =&gt; array(
           "id" =&gt; $_POST["value_id"],
           "from" =&gt; $_POST['value_from'],
           "to" =&gt; $_POST['value_to'],
           "desc" =&gt; $_POST['value_desc'],
           "customClass" =&gt; $_POST['value_class'],
           "label" =&gt; $_POST['value_label']
          )
      ); //you might need to process any other post fields you have..
  
  $json = json_encode( $postArray );
  array_push($json, $postArray);
  // write to file
  file_put_contents( $file, $json, FILE_APPEND);
  </code></pre>
  
  <p>I also can't establish the square bracket after <code>value</code>. How can I fix this?</p>