Skip to main content

escape_script_json

Function escape_script_json 

Source
pub fn escape_script_json(value: impl AsRef<str>) -> String
Expand description

Escapes a JSON string fragment before embedding it in an inline <script> context.

Call this after JSON serialization when the resulting text is inserted into a script block. It prevents HTML parser breakouts through </script>-relevant characters and preserves the JavaScript line terminator semantics of U+2028 and U+2029.