php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66021 Blank line inside empty array/object when JSON_PRETTY_PRINT is set
Submitted: 2013-11-02 18:27 UTC Modified: -
From: pleasestand at live dot com Assigned:
Status: Closed Package: JSON related
PHP Version: master-Git-2013-11-02 (Git) OS:
Private report: No CVE-ID: None
 [2013-11-02 18:27 UTC] pleasestand at live dot com
Description:
------------
The JSON_PRETTY_PRINT option to json_encode() causes a blank line to be inserted between the brackets or braces of an empty array or object. This is not how one would write out JSON by hand. Furthermore, it is inconsistent with JavaScript's JSON.stringify() and Python's json.dumps().

I think this may be unintentional because there is no test that shows the author of cb9c8233fc2d (r303425) had considered these cases (and chose not to put the brackets/braces on the same line).

I will submit a GitHub pull request shortly to fix this.

Test script:
---------------
<?php
echo json_encode([[],(object)[]], JSON_PRETTY_PRINT), "\n";

Expected result:
----------------
[
    [],
    {}
]

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

    ],
    {

    }
]

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-14 01:56 UTC] stas@php.net
Automatic comment on behalf of pleasestand@live.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=82a4f1a1a287d9dbf01156bc14ceb13ccbf16d7a
Log: Fix #66021 (Blank line inside empty array/object)
 [2014-04-14 01:56 UTC] stas@php.net
-Status: Open +Status: Closed
 [2014-04-15 12:04 UTC] ab@php.net
Automatic comment on behalf of pleasestand@live.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=82a4f1a1a287d9dbf01156bc14ceb13ccbf16d7a
Log: Fix #66021 (Blank line inside empty array/object)
 [2014-04-15 13:05 UTC] ab@php.net
Automatic comment on behalf of pleasestand@live.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=82a4f1a1a287d9dbf01156bc14ceb13ccbf16d7a
Log: Fix #66021 (Blank line inside empty array/object)
 [2014-05-01 14:59 UTC] tyrael@php.net
Automatic comment on behalf of pleasestand@live.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=82a4f1a1a287d9dbf01156bc14ceb13ccbf16d7a
Log: Fix #66021 (Blank line inside empty array/object)
 [2014-10-07 23:16 UTC] stas@php.net
Automatic comment on behalf of pleasestand@live.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=82a4f1a1a287d9dbf01156bc14ceb13ccbf16d7a
Log: Fix #66021 (Blank line inside empty array/object)
 [2014-10-07 23:27 UTC] stas@php.net
Automatic comment on behalf of pleasestand@live.com
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=82a4f1a1a287d9dbf01156bc14ceb13ccbf16d7a
Log: Fix #66021 (Blank line inside empty array/object)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC