Hi,

I am working on displaying my JSON string beautifully using jQuery.

Here is my code:

$(document).ready(function() {
    var jsonp = '[{"filename":"4x6_flower.png","count":1,"zones":[{"x":"198","y":"133","width":"1283","height":"820"}]}]';

    var obj = jQuery.parseJSON(jsonp);

    document.body.innerHTML = "";
    document.body.appendChild(document.createTextNode(JSON.stringify(obj, null, "\t")));
});

But output is displayed in a single line like this:

[ { "filename": "4x6_flower.png", "count": 1, "zones": [ { "x": "198", "y": "133", "width": "1283", "height": "820" } ] } ]

What should I do to make it displaying nicely?
(I can only use a js library with absolute url like jQuery - no extra files other than one html file. So please do not recommend me to use wierd js library that needs to be downloaded)

Member Avatar for diafol

Does taking off the first and last square bracket of jsonp help?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.