Question
Bapu Hirave · Apr 5, 2017

ZEN component to display JSON data

Hello,

is there some kind ZEN component available (e.g. tree or anything), which can display raw JSON string  data nicely on ZEN webpage ?

 

JSON string contains primary nodes, subnodes, arrays.

0
0 268
Discussion (2)0
Log in or sign up to continue

Hi Bapu,

There is a really simple solution, no Zen required.

Put some pre tags on your web page...

<pre id="json-preview-panel"></pre>

If your JSON is an object then...

document.getElementById("json-preview-panel").innerHTML=JSON.stringify(json, undefined, 2);

Note that the third argument in stringify() is the number of spaces to insert for prettifying.

If your JSON is a string already then you will need to convert it to an object and then back again...

document.getElementById("json-preview-panel").innerHTML=JSON.stringify(JSON.parse(json),undefined,2);

Sean.