Add new data into PHP JSON string
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 ? you need to json_decode($data) first, then add the new key/value, and json_encode() it. Ben I was just searching for the solution to this and stumbled across this question (already one year old). The answers provided so far were not very helpful to me. So, hopefully this helps the next person. The answer I was looking for was $json = json_decode($data,true); which returns the result in an array structure,