How can I display JSON in an easy-to-read (for human readers) format? I'm looking primarily for indentation and whitespace, with perhaps even colors / font-styles / etc.
相关问题
- Is there a limit to how many levels you can nest i
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- How to toggle on Order in ReactJS
- StackExchange API - Deserialize Date in JSON Respo
For debugging purpose I use:
I recommend using HighlightJS. It uses the same principle as the accepted answer, but works also for many other languages, and has many pre-defined colour schemes. If using RequireJS, you can generate a compatible module with
Generation relies on Python3 and Java. Add
-n
to generate a non-minified version.I use the JSONView Chrome extension (it is as pretty as it gets :):
Edit: added
jsonreport.js
I've also released an online stand-alone JSON pretty print viewer, jsonreport.js, that provides a human readable HTML5 report you can use to view any JSON data.
You can read more about the format in New JavaScript HTML5 Report Format.
Douglas Crockford's JSON in JavaScript library will pretty print JSON via the stringify method.
You may also find the answers to this older question useful: How can I pretty-print JSON in (unix) shell script?
Pretty-printing is implemented natively in
JSON.stringify()
. The third argument enables pretty printing and sets the spacing to use:If you need syntax highlighting, you might use some regex magic like so:
See in action here: jsfiddle
Or a full snippet provided below:
Use Newtonsoft.Json dll. this is work fine in IE and Chrome
put this code in your razor view