

Ask HN: Library to pretty print JSON? - x0ner

I feel like I am in Google Hell right now. Why is there not a readily available library that I could call to get a clean, pretty printing of my JSON return output within the browser.<p>The only thing I have stumbled across is:
http://www.cerny-online.com/<p>While it seems to do what I want, it looks for too chunky and complicated just to get some formatted JSON. Call me lazy, but a good old git clone and a function call would be nice.<p>Is there some buried treasure out there somewhere or do I need to write my own?
======
dazmiller
<http://code.google.com/p/jsonview/> for firefox.

[https://chrome.google.com/extensions/detail/ddngkjbldiejbhei...](https://chrome.google.com/extensions/detail/ddngkjbldiejbheifcmnfmmfiniimbbg?hl=en-
gb) for chrome.

There is also a website that does a decent job as well
<http://jsonviewer.stack.hu/>

All very nice viewers mate.

~~~
x0ner
Viewers yes, but I need something that takes the JSON returned from an AJAX
call and gives me a nice view of it. So it needs to be something I can call
through an API or locally.

~~~
dazmiller
i dont quite understand, the plugins allow you to view the resultant JSON from
an ajax request. Sorry for misunderstanding.

The Firefox plugin states:

Normally when encountering a JSON document (content type "application/json"),
Firefox simply prompts you to download the view. With the JSONView extension,
JSON documents are shown in the browser similar to how XML documents are
shown. The document is formatted, highlighted, and arrays and objects can be
collapsed. Even if the JSON document contains errors, JSONView will still show
the raw text.

------
_pius
The JSON reference implementation [1] does this with JSON.stringify.

[1] <https://github.com/douglascrockford/JSON-js>

------
makecheck
The Python standard library's "pprint" pretty-prints data structures...it
might work for JSON, since it looks basically the same (though I've never
tried).

------
krisneuharth
I use this a ton: <http://www.jsonlint.com/>

