Bug #66021 [Opn->Csd]: Blank line inside empty array/object when JSON_PRETTY_PRINT is set

From: Date: Mon, 14 Apr 2014 01:56:37 +0000
Subject: Bug #66021 [Opn->Csd]: Blank line inside empty array/object when JSON_PRETTY_PRINT is set
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185233@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66021&edit=1 ID: 66021 Updated by: stas@php.net Reported by: pleasestand at live dot com Summary: Blank line inside empty array/object when JSON_PRETTY_PRINT is set -Status: Open +Status: Closed Type: Bug Package: JSON related PHP Version: master-Git-2013-11-02 (Git) Block user comment: N Private report: N New Comment: 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) Previous Comments: ------------------------------------------------------------------------ [2013-11-02 18:27:11] 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: -------------- [ [ ], { } ] ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66021&edit=1

« previous php.bugs (#185233) next »