I know how to beautify JSON programmatically using javascript. this way we can achieve:
var obj = {"hello":"world", "Test":["hello"]}
document.body.innerHTML = "";
document.body.appendChild(document.createTextNode(JSON.stringify(obj, null, 4)));
But i tried to do it in angular js. but i am unable to achieve this. This is my step :
<div class="btn btn-primary" ng-click="test()">Press</div>
<textarea json-formatter rows="20" cols="140" ng-model="json">
</textarea>
$scope.test=function(){
var json=JSON.stringify($scope.json, null, "\t");
/*here if $scope.json is {"hello":"world", "Test":["hello"]}
then json return "{\"hello\":\"world\", \"Test\":[\"hello\"]}" */
}
here if $scope.json is {"hello":"world", "Test":["hello"]}
then json return "{\"hello\":\"world\", \"Test\":[\"hello\"]}" .after that, i don't now how to display beautify json to same text area. How to resolve this problem. Is there any other approach then please suggest me ?
jsonis already a string so stringifying it isn't going to work properly. TryJSON.stringify(JSON.parse($scope.json), null, "\t")