Expand description
Python json.dumps-shaped writers over serde_json::Value
(PORT-CONTRACT.d/07 §1).
Two dialects:
dumps_indent2—json.dumps(x, indent=2): bare,before the newline,": "key separator,ensure_ascii=True(\uXXXXescapes, surrogate pairs for astral), empty[]/{}inline, insertion-order keys, floats viapy_float_repr, no trailing newline (the caller’sprintadds it).dumps_compact— theexport --documentsJSONL dialect:json.dumps(x, ensure_ascii=False)= separators", "/": ", raw UTF-8 for non-ASCII.
Int vs float: a serde_json::Number holding an i64/u64 renders in
Python int form (2); one holding an f64 renders in float form
(2.0, 1e-05, …). serde_json preserves that distinction through
parsing ("2" parses integral, "2.0" parses as f64), and
serde_json::Number::from_f64 always yields the float variant — use
py_float to force float form for whole values when building
payloads (e.g. a computed 2.0 must not collapse to 2).
Functions§
- dumps_
canonical_ sorted json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)— the canonical digest dialect (agent-rules provenance digest): keys sorted (code-point order, like Pythonstr<), no separator spaces, raw UTF-8. No trailing newline.- dumps_
compact json.dumps(value, ensure_ascii=False)— compact separators (", "item,": "key), raw UTF-8. No trailing newline.- dumps_
indent2 json.dumps(value, indent=2)(ensure_ascii=True). No trailing newline.- dumps_
indent2_ no_ ascii json.dumps(value, indent=2, ensure_ascii=False)— raw UTF-8 output (thedecided coverageJSON contract). No trailing newline.- py_
float - Build a
Valuethat always serializes in Python float form (2.0), never as an int. Panics on NaN/infinity, whichjson.dumpscannot round-trip and which never occur in covered payloads.