I have a string json object that I am trying to format and display in the html. I have tried using JSON.parse()
and JSON.stringify()
but the typeof is still showing as a string and it is displaying in a straight line instead of formatting . I also tried <pre> {{formatJson | json}}</pre>
and still no success.
formatJSON: string = '{"a":1,"b":2,"c":{"d":3, "e":4}}'
ngOnInit() {
var test = json.parse(this.formatJSON);
console.log(typeof test); //string
this.formatJSON = JSON.stringify(test, null, " ")
}
HTML Code:
<div>
<textarea [(ngModel)]="formatJSON" class="text-area" cols="200" rows="10">
{{formatJSON}}
</textarea>
</div>
<!-- <pre>{{formatJSON | json}}</pre> -->
Desired Output: