Need help debugging a huge chunk of JSON data...

Posted by meder on Stack Overflow See other posts from Stack Overflow or by meder
Published on 2010-06-15T17:55:22Z Indexed on 2010/06/15 19:42 UTC
Read the original article Hit count: 160

Filed under:
|

I have a huge chunk, so large that I can't manually edit the file and need to read it in and do regex operations to see what's wrong.

Basically - my server is PHP 5.1.6 and I can't update it. This features an older json_decode which is less featured than the 5.2/5.3 versions.

json_decode returns NULL and json_last_error is being invoked but the function doesn't exist except in PHP 5.3 so I'm manually trying to see what's wrong.

$regex = '#[^0-9"$a-zA-Z{:}().]#';
$json = preg_replace( $regex, '', $json );
$tree = json_decode ( $json, true );

var_dump($tree); // NULL

A snippet of the JSON.. somewhere in the middle

{"109":0,"103":1,"102":59,"101":70,"100":4299,"94":0,"50":51,"46":0,"45":0,"44":0,"43":0,"42":0,"23":0,"22":0,"18":0,"17":1,"16":1,"13":160,"8":4298}},"2":{"d":{"109":0,"103":92,"102":54,"101":53,"100":4301,"94":0,"50":4278,"49":328,"46":1,"45":0,"44":1,"43":0,"42":0,"26":0,"23":0,"22":0,"18":0,"17":1,"16":1,"8":4300},"m":{"94":1,"100":1,"26":1,"50":1,"8":1,"49":1,"18":1,"43":1,"42":1,"109":1},"c":{"\/":{"d":{"109":0,"100":4301,"94":0,"50":4278,"49":328,"43":0,"42":0,"26":0,"18":0,"8":4300}},"G":{"d":{"109":1,"100":4303,"94":1,"68":17,"50":64,"49":53,"43":1,"42":1,"34":0,"18":1,"13":2216,"11":0,"8":4302}}}},"3":

The }}}} is suspicious but this probably just closes 4 nested object literals.

Would appreciate any insight.

© Stack Overflow or respective owner

Related posts about php

Related posts about JSON