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 “//”.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of json

json

Photo of HTML SCRIPT elements

HTML SCRIPT elements

Related news:

News photo

Json2dir: a JSON-to-directory converter, a fast alternative to home-manager

News photo

Spotting base64 encoded JSON, certificates, and private keys

News photo

JSON is not a YAML subset (2022)