Skip to main content

Module json

Module json 

Source
Expand description

Lossy JSON output — best-effort, for piping to jq and human eyes.

CBOR carries types JSON can’t represent losslessly (int variants beyond ±2^53, byte strings, tagged values). This writer makes a clean best-effort:

  • Integers print as JSON numbers when they fit in i64; otherwise as decimal strings.
  • Floats print as JSON numbers (NaN/Inf → null, which is what serde_json does too).
  • Byte strings render as "0x<hex>" — strings, not numbers, so they survive JSON-aware tools.
  • Tagged values render their inner value; the tag is dropped. Use cbor-diag when the tag matters.

Functions§

write_list
write_record
write_record_map
write_scalar
write_value