Skip to main content

escape_json

Function escape_json 

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

Escape a string as a JSON string body (RFC 8259).

Handles the required escapes (", \, and every C0 control character — \n/\t/\r/\b/\f by name, the rest as \uXXXX), so the result is always valid between JSON double quotes. Unlike escape_string (which targets beancount source and leaves control bytes other than \n/\t/\r raw), this never emits a bare control character — use it for JSON egress of user-controlled text (e.g. metadata-derived labels), which may carry an arbitrary control byte the parser preserved.