Req #52525 [Opn->Dup]: Add a PRETTY_PRINT flag or argument to json_encode

From: Date: Thu, 16 Sep 2010 13:54:27 +0000
Subject: Req #52525 [Opn->Dup]: Add a PRETTY_PRINT flag or argument to json_encode
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-154424@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52525&edit=1 ID: 52525 Updated by: aharvey@php.net Reported by: T dot J dot Hunt at open dot ac dot uk Summary: Add a PRETTY_PRINT flag or argument to json_encode -Status: Open +Status: Duplicate Type: Feature/Change Request Package: JSON related Operating System: Any PHP Version: 5.2.14 Block user comment: N New Comment: Duplicate of request #44331. Previous Comments: ------------------------------------------------------------------------ [2010-08-03 18:10:01] T dot J dot Hunt at open dot ac dot uk Description: ------------ When trying to debug a large amount of JSON output that has been created using json_encode, it would be really nice to have an option to format the output beautifully, with some line-breaks and indenting, so the the generated JSON is easier to read. Something a bit like the output of print_r. Test script: --------------- $bigarray = array(); for ($i = 0; $i < 100; $i++) { $bigarray['key' . $i] = 'value' . $i; } echo json_encode($bigarray, JSON_PRETTY_PRINT); // Will error, because I made up the JSON_PRETTY_PRINT constant name. Expected result: ---------------- { "key0":"value0", "key1":"value1", "key2":"value2", ... } Actual result: -------------- {"key0":"value0","key1":"value1","key2":"value2",... ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=52525&edit=1

« previous php.bugs (#154424) next »