Req #52525 [NEW]: Add a PRETTY_PRINT flag or argument to json_encode

From: Date: Tue, 03 Aug 2010 16:10:01 +0000
Subject: Req #52525 [NEW]: Add a PRETTY_PRINT flag or argument to json_encode
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-153063@lists.php.net to get a copy of this message
From:             
Operating system: Any
PHP version:      5.2.14
Package:          JSON related
Bug Type:         Feature/Change Request
Bug description:Add a PRETTY_PRINT flag or argument to json_encode

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 bug report at http://bugs.php.net/bug.php?id=52525&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=52525&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=52525&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=52525&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=52525&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52525&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=52525&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=52525&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=52525&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=52525&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=52525&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=52525&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=52525&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=52525&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=52525&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=52525&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=52525&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=52525&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=52525&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=52525&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=52525&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=52525&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#153063) next »