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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Mon Dec 02 18:01:31 2024 UTC