Get the latest tech news
How to safely escape JSON inside HTML SCRIPT elements
<script> tags follow unintuitive parsing rules that can break a webpage in surprising ways. Fortunately, it’s relatively straightforward to escape JSON for script tags.
<script> tags follow unintuitive parsing rules that can break a webpage in surprising ways. This post will dive deep into the exotic script tag parsing rules in order to understand how they work and why this is the appropriate way to escape JSON. for related historical reasons, the string “<!–” in classic scripts is actually treated as a line comment start, just like “//”.
Or read this on Hacker News