php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52525 Add a PRETTY_PRINT flag or argument to json_encode
Submitted: 2010-08-03 18:10 UTC Modified: 2010-09-16 15:54 UTC
Votes:8
Avg. Score:3.8 ± 1.0
Reproduced:7 of 7 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (28.6%)
From: T dot J dot Hunt at open dot ac dot uk Assigned:
Status: Duplicate Package: JSON related
PHP Version: 5.2.14 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 21 = ?
Subscribe to this entry?

 
 [2010-08-03 18:10 UTC] 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",...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-16 15:54 UTC] aharvey@php.net
-Status: Open +Status: Duplicate
 [2010-09-16 15:54 UTC] aharvey@php.net
Duplicate of request #44331.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 21:01:28 2024 UTC