Bug #78765 [NEW]: enhancement to json_decode : treat a JSON string with duplicate keys as invalid
| From: | bas5winkel at gmail dot com | Date: | Thu, 31 Oct 2019 10:31:23 +0000 |
| Subject: | Bug #78765 [NEW]: enhancement to json_decode : treat a JSON string with duplicate keys as invalid | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-223530@lists.php.net to get a copy of this message | ||
From: bas5winkel at gmail dot com
Operating system: Debian
PHP version: 7.2.24
Package: JSON related
Bug Type: Bug
Bug description:enhancement to json_decode : treat a JSON string with duplicate keys as invalid
Description:
------------
Duplicate key names are not allowed in the JSON format.
If a json string containing duplicate keys is decoded with json_decode,
json_decode simple overwrites the existing key.
Just like json_encode returns NULL for other invalid JSON strings,
could such an input also be treated as invalid?
Maybe as an optional check as this is just a rare condition?
Test script:
---------------
<?php
echo
var_export(json_decode('{"a":"b","a":"c"}'),1);
?>
Expected result:
----------------
NULL or an exception
Actual result:
--------------
stdClass::__set_state(array(
'a' => 'c',
))
--
Edit bug report at https://bugs.php.net/bug.php?id=78765&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78765&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78765&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78765&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78765&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78765&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78765&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78765&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78765&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78765&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78765&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78765&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78765&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78765&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78765&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78765&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78765&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78765&r=mysqlcfg