Show nice json on html div..possible?

I already read this topic. How can I print JSON using JavaScript?

In any case, the correct answer just works if I want to print this json on the console.

Doing something like

$("#myDiv").text(parsedJson);

or

$("#myDiv").html(parsedJson);

won't lead to pretty json.

My intention is to display a dialog box containing this json object in a form accessible to humans. Is it possible?

+4
source share
2 answers

Unconfirmed, but you need to start:

$('#myDiv').append(
    $('<pre>').text(
        JSON.stringify(parsedJson, null, '  ')
    )
);
+11
source

You can use the tag <pre>instead div, assuming it parsedJsoncontains all newlines and indents.

+5
source

Source: https://habr.com/ru/post/1544755/


All Articles