pub fn json_string(text: &str) -> StringExpand description
What:
Encode text as a JSON string literal,
exactly as JSON.stringify would.
&str borrows the text;
String is the owned,
quoted result.
Why:
Messages contain file paths,
quotes and user-written keys.
Each character is
encoded at this final step so no value can break out of its JSON string or
its line:
quotes,
backslashes and every control character are escaped.
In TS you’d write (pseudocode):
function jsonString(text: string): string { return JSON.stringify(text); }