sNniffer
sNniffer

Reputation: 209

Print Variable Json PHP

I have a JSON

$data= '[
    {
        "opa": "maam",
        "clik": "7026981995",
        "pt": 123,
        "aaab": [{
            "ttt": "1.22",
            "tt": [{
                "aaa2": 1.2277,
                "aaa122": 19811225
            }]
        }]
    },
    {
        "opaa": "maam1",
        "clik1": "7026981995",
        "pt1": 123,
        "aaa11": [{
            "ttt1": "1.222",
            "tt1": [{
                "aaa1": 1.2277,
                "aaa3": 19811225
            }]
        }]
    }
]'

I need to print it on the screen, just as it is in the variable, I tried

echo json_encode($data, JSON_PRETTY_PRINT);

But, a pile is printed, not being readable.

Upvotes: 0

Views: 46

Answers (3)

Martin Zeitler
Martin Zeitler

Reputation: 76639

how about <pre>, which is the "preformatted text element"?

die('<pre>'.print_r(json_decode($data), true).'</pre>');

this would also work (which I'd assume is what you've meant):

die('<pre>'.$data.'</pre>');

Upvotes: 1

Tommys
Tommys

Reputation: 121

  1. change the code to:

    print_r(json_decode($data), true)

  2. Get JSON formater extension for chrome to prettify the json.

Upvotes: 0

WebD
WebD

Reputation: 705

It is already in json format. Just do:

echo $data;

Upvotes: 0

Related Questions