PHP code example of jdelta / pretty-json

1. Go to this page and download the library: Download jdelta/pretty-json library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jdelta / pretty-json example snippets




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>';