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. Just do this Replace < with \x3C or \u003C in JSON strings. with or in JSON strings. In PHP, use json_encode($data, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES) for safe JSON in <script> tags. for safe JSON in tags. In WordPress, use wp_json_encode with the same flags. You don’t have to take my word for it, the HTML standard recom