#44331 [Com]: Formatting option for json_encode
| From: | pankaj dot khairnar at live dot com | Date: | Tue, 08 Dec 2009 12:05:52 +0000 |
| Subject: | #44331 [Com]: Formatting option for json_encode | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-145522@lists.php.net to get a copy of this message | ||
ID: 44331
Comment by: pankaj dot khairnar at live dot com
Reported By: jeremy at duckwizard dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: Debian Stable
PHP Version: 5.2.5
New Comment:
yes it will be a real nice feature of json_encode function
and I am expecting it to same.
Previous Comments:
------------------------------------------------------------------------
[2008-03-04 20:05:37] jeremy at duckwizard dot com
Description:
------------
One of the appeals of JSON is that it is human readable. However,
json_encode produces output that is not particularly manageable by a
human - little more so than PHP's own serialization. DOM, for example,
has a formatOutput option that nicely indents the resulting XML. A
similar option for json_encode would be extremely helpful.
Reproduce code:
---------------
$obj = new stdClass;
$obj->field1 = "hello";
$obj->field2 = "world";
$obj->field3 = array("key" => "value", "level2" =>
array(1,2,3));
echo json_encode($obj, JSON::FORMAT_OUTPUT);
//flags are an implementation example
Expected result:
----------------
{
"field1":"hello",
"field2":"world",
"field3":
{
"key":"value",
"level2": [1,2,3]
}
}
Actual result:
--------------
{"field1":"hello","field2":"world","field3":{"key":"value","level2":[1,2,3]}}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44331&edit=1