<script> elements and in XML
For example, given
key2: ["user_input1", "user_input2"]
It preserves several properties:
- Keys must be properly quoted.
- Brackets match.
- Quotes (
"), backslashes (
\u.... escaped to ensure that strings do not end prematurely.
- Angle brackets (
\u.... escaped as necessary to prevent strings from containing the literal text
]]> which would prevent embedding.
- All control characters (actually characters not allowed in XML) are
\u.... escaped including U+0-U+1F excluding tab, U+7F, U+FFFE, U+FFFF.
- Orphaned UTF-16 surrogates are
- All escape sequences are converted to valid JSON escape sequences including octal escapes (
\012), two-digit hex escaped (
\x0A), and single character escapes (
It can be a good idea to
\u.... escape things like
+ to defang UTF-7.