Append data to Json from PHP
<p>I want to append <code>{ "pname":"superman" , "pid":"4" }</code>to the obdatabase.json. But my attempt below completely overwrite the json file.
How do I modify this?</p>

<p>obdatabase.json</p>

<pre><code>{ "pobject":[{ "pname":"Pikachu" , "pid":"1" },
{ "pname":"squirtle" , "pid":"2" },
{ "pname":"Justinbieber" , "pid":"3" }]}
</code></pre>

<p>add.php</p>

<pre><code>&lt;?php

$file="obdatabase.json";
$json = json_decode(file_get_contents($file),TRUE);

$json['pobject'] = array('pname'=&gt;'Superman', 'pid'=&gt;4);

file_put_contents('obdatabase.json', json_encode($json));

?&gt;
</code></pre>