php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57469 decode chokes on unquoted object keys
Submitted: 2007-01-05 08:43 UTC Modified: 2008-12-18 21:41 UTC
From: jan at horde dot org Assigned:
Status: Not a bug Package: json (PECL)
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2007-01-05 08:43 UTC] jan at horde dot org
Description:
------------
json_decode() fails completely on the following code:

Reproduce code:
---------------
var_dump(json_decode('[{0:"tan","model":"sedan"},{"0":"red",model:"sports"}]'));
var_dump(json_decode('{"1":"one",2:"two","5":\'fi"ve\'}'));

Expected result:
----------------
array(2) {
  [0]=>
  object(stdClass)(2) {
    [0]=>
    string(3) "tan"
    ["model"]=>
    string(5) "sedan"
  }
  [1]=>
  object(stdClass)(2) {
    [0]=>
    string(3) "red"
    ["model"]=>
    string(6) "sports"
  }
}
object(stdClass)(3) {
  [1]=>
  string(3) "one"
  [2]=>
  string(3) "two"
  [5]=>
  string(5) "fi"ve"
}


Actual result:
--------------
NULL
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-18 21:41 UTC] scottmac@php.net
The specification states that all keys are strings and 
therefore must be surrounded by quotes.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 08:01:25 2019 UTC