I have the following JSON file stored in a server. I am using a php script to add another object to this JSON file.
testjson1.json:
{
"feed":
[
{
"id": "1",
"name": "Ram",
"status": "Very good restaurant!! water tastes soo good :)"
}
]
}
The php that i use to add an object is as follows:
<?php
$data=array("2","new","not so good");
$inp = file_get_contents('testjson1.json');
$tempArray = json_decode($inp);
array_push($tempArray, $data);
$jsonData = json_encode($tempArray);
file_put_contents('testjson1.json', $jsonData);
?>
But the php file shows an error which says:
Warning: array_push() expects parameter 1 to be array, object given in /home/u160481344/public_html/jsonfinder.php on line 5
and the json file collapses into a single line. How can i solve this?