How to display dynamic string JSON into Div or Textarea in javascript

Viewed 26

I am calling an API it is returning the dynamic JSON, I want to just display this into the DIV or TEXTAREA.

JSON Can be : {"id":255,"Val2":"\n {"Id": 28, "deta": "\n {\n \"strategy1\":{\"$type\":\"Text1, text2\"}}"}"}

or

{"id":251,"name":"text", enable:true}

Expected result:


    {
      "id":255,
      "Val1":
       {
          Id: 28, 
          "deta": 
          {
            "strategy1":
            {
              "$type":"text1, text2"
            }
          }
       }
    }

1 Answers

( yoinked from the following answer already )

https://stackoverflow.com/a/7220510/20053031

const obj = resultOfYourRequest;
const prettyString = JSON.stringify(obj, null, 2);

document.getElementById('your-element-id').innerHtml = prettyString;
Related