JSON vs JS literal — what's actually different
JSON is a strict subset of JavaScript object literal syntax:
- JSON strings only support double quotes; JS accepts single, double or backticks.
- JSON only knows about
\",\\,\/,\b,\f,\n,\r,\t,\uXXXX. JS additionally knows\x,\u{…},\',\0. - JSON has no comments. JS does (this is irrelevant for a single string, but worth keeping in mind).
Picking JSON gives you output that's safe in either context. Picking JS gives you the more idiomatic form for a hand-written source file.