php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50166 json_encode returns wrong brackets for empty array
Submitted: 2009-11-13 13:59 UTC Modified: 2009-11-13 14:56 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: dumpbox at mail dot ru Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.2.11 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
29 + 50 = ?
Subscribe to this entry?

 
 [2009-11-13 13:59 UTC] dumpbox at mail dot ru
Description:
------------
By default json object starts with "{" and ends with "}"
Error occurs when user attempt encode empty array.


Reproduce code:
---------------
echo json_encode(array());

Expected result:
----------------
{}

Actual result:
--------------
[]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-13 14:56 UTC] jani@php.net
Yes, that would be an array in JSON. Please check http://www.json.org/ for the syntax. No bug here. (and yes, assoc arrays do end up as objects..)

Like this:

[jani@localhost ~]$ php -r 'var_dump(json_encode(array("foo" => "bar")));'
string(13) "{"foo":"bar"}"
[jani@localhost ~]$ php -r 'var_dump(json_encode(array("foo", "bar")));'
string(13) "["foo","bar"]"


No bug here.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 07:01:29 2024 UTC