Skip to main content

write_json

Function write_json 

Source
pub fn write_json(
    doc: &Doc,
    indent: Option<usize>,
    strict: bool,
    report: Option<&mut WriteReport>,
) -> Result<String, WriteError>
Expand description

Project a Doc to JSON text.

indent: None writes compact JSON (, /: separators, single line); indent: Some(n) pretty-prints with n spaces per level, matching Python’s indent= parameter. A NaN/Infinity/-Infinity leaf now fails the write unconditionally (write.unsupported-value, spec Sec8.3.8/Sec8.3.9 updated 2026-08-24) – regardless of strict – rather than substituting null and reporting an adjustment: writing a genuine null and writing NaN used to produce the identical JSON null token, so a substituted NaN was indistinguishable from an original null on read-back (confirmed live). See this module’s doc comment on why no temporal adjustment is needed.