Retrieve and Update JSON Object Using PHP CODE

I`m doing offline chat application, this application needs to work on Online and Offline. If i`m in Offline means the data are stored in localStorage after connecting Internet it synchronize with server, here i`m using php as a server side script.

The problem i need to append my json object to json file...
below i have enclosed my json file..