StackSN StackSN - 9 days ago 5
JSON Question

Parsing non standard JSON in PHP

This is a non standard

json
format api :

WebInfo ({
"name": "Google",
"code": 1,
"domain": "http://www.google.com/",
})


as the data is not a standard JSON,
json_decode()
can not be resolved directly, what can I do to make it become a valid
json
format ?

Answer

You will have to strip out WebInfo ( and ) which can be done by using str_replace()

Try this: Lets assume your string that has WebInfo({...}) is $str then do this:

$str = str_replace('MusicInfoCallback(', '', $str); 
$str = str_replace(' )', '', $str);
print_r(json_decode($str, true));