I've a json structure :
{
"Photos":{
"Photo":[
{
"ID" : 111,
"type" : "JPEG",
"URL": "blabla"
},
{
"ID": 222,
"type": "JPG",
"URL": "blaaaaaaaaa"
}
]
}
}
Am attempting to use php-jsonpath (By stefan Goessner : http://goessner.net/articles/JsonPath) to fetch node (photo) where ID == 222. And then, if found, insert a new data (array) into that node. Such that final output becomes :
{
"Photos":{
"Photo":[
{
"ID" : 111,
"type" : "JPEG",
"URL": "blabla"
},
{
"ID": 222,
"type": "JPG",
"URL": "blaaaaaaaaa",
"New_data" : {"CROP": "5x7", "Pixel": "none"}
}
]
}
}
currently i have this query string:
$parser = new Services_JSON(SERVICE_JSON_LOOSE_TYPE);
$jsonobj = $parser->decode(file_get_contents("filename.json", true));
$result = jsonPath($jsonobj , "$..Photo[?(@.ID == 222)]"); //is this expression wrong ?
i am only expectant of the node with the said ID (222) as returned $result, so that i can do this :
if($result != false){
$result[] = array("New_data" => array("CROP" => 5x7, "Pixel" => "none"));
}
Unfortunately i go the error message :
Notice: Array to string conversion in C:\Server\wamp\www\MyCMS\jsonpath.php(119)
What sin am i commiting ? and how do i get around it ? any code snippet (if necessary) will be appreciated. thanks !