How to display information from a JSON file in the browser in a friendly way?

5

The application receives a JSON file, already validated, and should display it to the user who is a programmer.

I would like to display the JSON as in this validation site and beautify JSON .

So I wanted this JSON:

{"glossary": {
        "title": "example glossary",
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    },
                    "GlossSee": "markup"}}}}
}

It was displayed as follows to make it more readable for the programmer, like this:

Note that there is a possibility of expanding or not the node.

Does anyone know of any applications that do this?

Note: I'm using php.

    
asked by anonymous 19.07.2017 / 17:35

2 answers

1

install the composer package var-dumper .

add the line:

dd(json_decode($seu_json));

If the data comes in array just pass the parameter inside the dd() :

dd($seu_array);

result:

This way you can minimize and maximize information on the screen

    
19.07.2017 / 20:04
5

If you are using a version of PHP that is 5.4+, you can use the JSON_PRETTY_PRINT constant of the json_econde () method. Here's an example:

$a = ['cor'=> 'azul', 'largura' => '120', 'modelo' => 'A'];
echo json_encode($a, JSON_PRETTY_PRINT);

More information at: link

    
19.07.2017 / 18:52