From: coyote4til7 at gmail dot com Operating system: Linux PHP version: 5.2.6 PHP Bug Type: JSON related Bug description: json_decode fails on json representing javascript objects
Description: ------------ When you encode a proper javascript object as json and then use the json_decode function, it fails. The keys in Javascript objects are _not_ supposed to be quoted. If you're going to store a json-encoded object (say in a database) and then reuse it later in javascript, quoting the keys so that php's json_decode function works means that you're counting on the browser's javascript to support something that is not supported by the javascript specification. Reproduce code: --------------- // In javascript, we have an object: // var obj = { parent_id:-1,label:"label" }; // // In javascript, the keys for objects are _not_ quoted by // single or double quotes. So, if we're going to properly encode // this to later reuse it in javascript, we get this sent to php: $json = '[{parent_id:-1,label:"label"}]'; // Let's try to convert it: var_dump(json_decode($json, true)); Expected result: ---------------- { ["parent_id"]=> int(-1) ["label"]=> string(5) "label" } Actual result: -------------- NULL -- Edit bug report at http://bugs.php.net/?id=45563&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45563&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45563&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45563&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45563&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45563&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45563&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45563&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45563&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45563&r=support Expected behavior: http://bugs.php.net/fix.php?id=45563&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45563&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45563&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45563&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45563&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45563&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45563&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45563&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45563&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45563&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45563&r=mysqlcfg