public static function format($json, $html = false)
    {
        $format = str_replace(
            [
                '    ',
                '\/',
            ], [
                '  ',
                '/',
            ], json_encode(
                json_decode(
                    str_replace(
                        [
                            "\n",
                            '  ',
                            ', }',
                            ', ]',
                            ',}',
                            ',]',
                        ],
                        [
                            '',
                            '',
                            '}',
                            '}',
                            '}',
                            ']',
                        ],
                        $json
                    )
                ),
                JSON_PRETTY_PRINT
            )
        );

        if ($html) {
            return str_replace("\n", '<br/>', $format);
        }

        return $format;
    }
public static function format($json, $html = false)
    {
        $format = str_replace(
            [
                '    ',
                '\/',
            ], [
                '  ',
                '/',
            ], json_encode(
                json_decode(
                    str_replace(
                        [
                            "\n",
                            '  ',
                            ', }',
                            ', ]',
                            ',}',
                            ',]',
                        ],
                        [
                            '',
                            '',
                            '}',
                            '}',
                            '}',
                            ']',
                        ],
                        $json
                    )
                ),
                JSON_PRETTY_PRINT
            )
        );

        if ($html) {
            return str_replace("\n", '<br/>', $format);
        }

        return $format;
    }
public static function format ( $ json , $ html = false ) { $ format = str_replace ( [ '    ' , '\/' , ] , [ '  ' , '/' , ] , json_encode ( json_decode ( str_replace ( [ "\n" , '  ' , ', }' , ', ]' , ',}' , ',]' , ] , [ '' , '' , '}' , '}' , '}' , ']' , ] , $ json ) ) , JSON_PRETTY_PRINT ) ) ; if ( $ html ) { return str_replace ( "\n" , '<br/>' , $ format ) ; } return $ format ; }
Indents a flat JSON string to make it more human-readable
Use php function JSON_PRETTY_PRINT. Require php >= 5.4

@param string  $json The original JSON string to process
@param boolean $html If true, return the JSON in a format suitable for display in a web browser
Default: false

@return string Indented version of the original JSON string
Indents a flat JSON string to make it more human - readable Use php function JSON_PRETTY_PRINT . Require php > = 5 . 4