|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76795 json_encode option that outputs associative arrays as arrays instad of objects
Submitted: 2018-08-26 12:56 UTC Modified: 2018-08-29 22:00 UTC
From: kenny dot retzlaff at gmail dot com Assigned:
Status: Suspended Package: JSON related
PHP Version: 7.2.9 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kenny dot retzlaff at gmail dot com
New email:
PHP Version: OS:


 [2018-08-26 12:56 UTC] kenny dot retzlaff at gmail dot com
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.

$obj = array("key1" => "value", "key2" => "value2");
json_encode($obj, JSON_FORCE_ARRAY); // ["value", "value2"]


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-26 13:11 UTC]
javascript does not do "associative arrays" like PHP so what you are asking for is not valid JSON.
 [2018-08-26 13:12 UTC]
Actually when reading what you are asking for again it's just:


So imo no need to introduce yet another constant for something you can already easily do with the existing tooling.
 [2018-08-29 22:00 UTC]
-Status: Open +Status: Suspended
 [2018-08-29 22:00 UTC]
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] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Nov 29 08:03:14 2021 UTC