From: jeremy at duckwizard dot com
Operating system: Debian Stable
PHP version: 5.2.5
PHP Bug Type: Feature/Change Request
Bug description: Formatting option for json_encode
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 bug report at http://bugs.php.net/?id=44331&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44331&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44331&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44331&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44331&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44331&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44331&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44331&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44331&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44331&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44331&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44331&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44331&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44331&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44331&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44331&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44331&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44331&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44331&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44331&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44331&r=mysqlcfg