3 ms·
Ask HN: Library to pretty print JSON?
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.
The only thing I have stumbled across is:
http://www.cerny-online.com/
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.
Is there some buried treasure out there somewhere or do I need to write my own?
- makecheck 16y agoThe 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).
- dazmiller 16y agohttp://code.google.com/p/jsonview/ http://code.google.com/p/jsonview/ for firefox. https://chrome.google.com/extensions/detail/ddngkjbldiejbheifcmnfmmfiniimbbg?hl=en-gb https://chrome.google.com/extensions/detail/ddngkjbldiejbhei... for chrome. There is also a website that does a decent job as well http://jsonviewer.stack.hu/ http://jsonviewer.stack.hu/ All very nice viewers mate.
- x0ner 16y agoViewers 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 16y agoi 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 16y agoThe JSON reference implementation [1] does this with JSON.stringify. [1] https://github.com/douglascrockford/JSON-js https://github.com/douglascrockford/JSON-js
- krisneuharth 16y agoI use this a ton: http://www.jsonlint.com/ http://www.jsonlint.com/