tags:

views:

98

answers:

2

Hello. I have $data as JSON encoded data and I have this string:

$new_data = "color:'red'";

that needs to be added to $data so that I can read it from it as a json string.

How can I achieve this ?

Thank you.

+6  A: 

you need to json_decode($data) first, then add the new key/value, and json_encode() it.

cloudhead
+2  A: 
$dataToAugment = json_decode($data);

// add you data here at the proper position

$data = json_encode($dataToAugment);
Eineki