I have the following JSON formatted string:
{
"hooks":[
{
"type":"subscribe",
"id":1331741592.6925,
"email":"JoeX@test-email.com",
"status":"Active",
"custom_fields":"{\"first_name\":\"Joe\",\"last_name\":\"X\"}",
"ip_created":"24.199.200.142",
"list_id":"33",
"list_type":"internal",
"list_name":"Administrator List 2",
"list_optin":false
},
{
"type":"subscribe",
"id":1331741592.7067,
"email":"JaneY@test-email.com",
"status":"Active",
"custom_fields":"{\"first_name\": \"Jane\",\"last_name\":\"Y\"}",
"ip_created":"24.199.200.142",
"list_id":"33",
"list_type":"internal",
"list_name":"Administrator List 2",
"list_optin":false
}
]
}
I want to use the PHP json_decode()
function to put it in an associative array.
When I do run the script, debugging shows the value of the new array as null
, so I presume the decode is failing. We aren't running PHP 5.3, so I can't use json_last_error()
. Here is the code:
$hooks = (the JSON string from above);
$hooksArray = json_decode($hooks, true);
Any ideas why the $hooksArray
is coming back null
?