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
Here is a simple JSON format/color component written in React:
See it working in this CodePen: https://codepen.io/benshope/pen/BxVpjo
Hope that helps!
If you need this to work in a textarea the accepted solution will not work.
<textarea id='textarea'></textarea>
$("#textarea").append(formatJSON(JSON.stringify(jsonobject),true));
I ran into an issue today with @Pumbaa80's code. I'm trying to apply JSON syntax highlighting to data that I'm rendering in a Mithril view, so I need to create DOM nodes for everything in the
JSON.stringify
output.I split the really long regex into its component parts as well.
Code in context on Github here
If you use net.sf.json, you can pretty print as follows (using a 4 space indentation):
In case of displaying in HTML, you should to add a balise
<pre></pre>
Example:
It works well:
Read more here: https://developer.mozilla.org/pt-BR/docs/Web/API/Console/table