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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dumpbox at mail dot ru
New email:
PHP Version: OS:

 

 [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: Fri Mar 29 06:01:29 2024 UTC