Skip to main content

json_string

Function json_string 

Source
pub fn json_string(s: &str) -> String
Expand description

Render s as a double-quoted JSON string literal, escaping the two structural characters (" and \) and the whole C0 control range.

The C0 range matters and is easy to forget: RFC 8259 forbids an unescaped character below U+0020 inside a string, so a stray newline or NUL is the difference between a manifest that parses and one that merely usually parses. Characters at or above U+0020 pass through as-is — the output is UTF-8 JSON, so there is no reason to \u-escape non-ASCII.