Req #76795 [Opn->Sus]: json_encode option that outputs associative arrays as arrays instad of objects
| From: | cmb@php.net | Date: | Wed, 29 Aug 2018 22:00:47 +0000 |
| Subject: | Req #76795 [Opn->Sus]: json_encode option that outputs associative arrays as arrays instad of objects | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216792@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76795&edit=1
ID: 76795
Updated by: cmb@php.net
Reported by: kenny dot retzlaff at gmail dot com
Summary: json_encode option that outputs associative arrays
as arrays instad of objects
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: JSON related
Operating System: *
PHP Version: 7.2.9
Block user comment: N
Private report: N
New Comment:
In my opinion, a general array_values_recursive() *might* be more
sensible. Anyhow, this feature clearly needs discussion on the
internals@ mailing list (and maybe even an RFC[1]). For the time
being, I'm suspending this request.
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2018-08-26 13:12:53] peehaa@php.net
Actually when reading what you are asking for again it's just:
json_encode(array_values($obj));
So imo no need to introduce yet another constant for something you can already easily do with the
existing tooling.
------------------------------------------------------------------------
[2018-08-26 13:11:39] peehaa@php.net
javascript does not do "associative arrays" like PHP so what you are asking for is not
valid JSON.
------------------------------------------------------------------------
[2018-08-26 12:56:56] kenny dot retzlaff at gmail dot com
Description:
------------
Introduce an json_encode option that ignores all keys of associative arrays and writes the json
object in the [] syntax instead of the {} syntax. Without having to use array_values(). So it can be
used in objects that contain multiple arrays.
E.g.
$obj = array("key1" => "value", "key2" => "value2");
json_encode($obj, JSON_FORCE_ARRAY); // ["value", "value2"]
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76795&edit=1