I checked many questions but didn't see a solution.
I have JSON which was STRINGIFIED (containing HTML).
This JSON is stored as a string on an element.
When I try to JSON.parse(str) I am getting errors
I know that the errors are due to the special symbols \n \t etc and has to be escaped. So how to parse this string which is the JSON and have it as an object.
var obj = {
"blocks": [{
"frames_content": "<div id=\"page\" class=\"page\">\n \n \t<div class=\"container\" id=\"divider1\">\n \n \t\t<div class=\"col-md-12\">\n \n \t\t\t<hr class=\"dashed\" data-selector=\"hr.dashed\" style=\"outline: none; cursor: inherit;\">\n \t\n \t\t</div><!-- /.col -->\n \t\n \t</div><!-- /.container -->\n \n </div>",
"frames_sandbox": false,
"frames_loaderFunction": "",
"frames_height": 162,
"frames_original_url": "/static/admin-users/pages/elements/divider1.html"
}]
};
document.getElementById("debug").innerHTML = JSON.stringify(obj);
var str = document.getElementById("debug").innerHTML;
var x = JSON.parse(str);
console.log(x);
<div id="debug"></div>
===== UPDATE
If I read the element with .text() works
I have one more scenario which I don't get how to solve
<script>
var str = '{"pages":{"index":{"blocks":[{"frames_content":"<div id=\"page\" class=\"page\">\n \n \t<div class=\"container\" id=\"divider1\">\n \n \t\t<div class=\"col-md-12\">\n \n \t\t\t<hr class=\"dashed\" data-selector=\"hr.dashed\" style=\"outline: none; cursor: inherit;\">\n \t\n \t\t</div><!-- /.col -->\n \t\n \t</div><!-- /.container -->\n \n </div>","frames_sandbox":false,"frames_loaderFunction":"","frames_height":162,"frames_original_url":"/static/admin-users/pages/elements/divider1.html"}]}},"responsiveMode":"desktop"}';
var obj = JSON.parse(str);
</script>
Should I escape them with REGEX or what ? What is the best way ?
text()instead ofhtml()