Skip to main content

Module cli_ndjson_safe_stringify

Module cli_ndjson_safe_stringify 

Source
Expand description

NDJSON-safe JSON serialization.

JSON.stringify emits U+2028/U+2029 raw (valid per ECMA-404). When the output is a single NDJSON line, any receiver that uses JavaScript line-terminator semantics (ECMA-262 §11.3 — \n \r U+2028 U+2029) to split the stream will cut the JSON mid-string.

The \uXXXX form is equivalent JSON but can never be mistaken for a line terminator by ANY receiver.

Functions§

escape_unicode_line_separators
Escape U+2028/U+2029 in an arbitrary string (not just JSON). Useful for session transcript content that may contain these characters.
serialize_to_ndjson
Serialize any serde value to NDJSON-safe JSON.
serialize_to_ndjson_safe
Serialize a JSON value to NDJSON-safe string, falling back to empty string on error.