I have the following file:
data.txt
{name:yekky}{name:mussie}{name:jessecasicas}
I am quite new at PHP. Do you know how I can use the decode the above JSON using PHP?
My PHP code
var_dump(json_decode('data.txt', true));// var_dump value null
foreach ($data->name as $result) {
echo $result.'<br />';
}
json_decode takes a string as an argument. Read in the file with
file_get_contents
You do need to adjust your sample string to be valid JSON by adding quotes around strings, commas between objects and placing the objects inside a containing array (or object).