jdelta / pretty-json
The new JSON pretty print approach.
v1.0
2018-04-18 16:38 UTC
This package is auto-updated.
Last update: 2025-03-25 07:47:00 UTC
README
The new JSON pretty print approach.
Example:
require __DIR__ . '/../vendor/autoload.php'; use jDelta\PrettyJson; $myData = [ 'service_url' => 'http://example.com/api/my-friends', 'success' => true, 'data' => [ ['id'=>1, 'name'=>'Bill Gates', 'age' => 62], ['id'=>2, 'name'=>'Elon Musk', 'age' => 46], ['id'=>3, 'name'=>'Mark Zuckerberg', 'age' => 33] ], 'total' => 3, 'response_time' => '0.0014s' ]; //Before echo '<pre>'; echo json_encode($myData, JSON_PRETTY_PRINT); echo '</pre>'; //Now echo '<pre>'; echo PrettyJson::getPrettyPrint(json_encode($myData)); echo '</pre>';
Result before:
{ "service_url": "http:\/\/example.com\/api\/my-friends", "success": true, "data": [ { "id": 1, "name": "Bill Gates", "age": 62 }, { "id": 2, "name": "Elon Musk", "age": 46 }, { "id": 3, "name": "Mark Zuckerberg", "age": 33 } ], "total": 3, "response_time": "0.0014s" }
Result now:
{ "service_url": "http://example.com/api/my-friends", "success": true, "data": [ {"id": 1, "name": "Bill Gates", "age": 62}, {"id": 2, "name": "Elon Musk", "age": 46}, {"id": 3, "name": "Mark Zuckerberg", "age": 33} ], "total": 3, "response_time": "0.0014s" }