Expand description
json_minify transform (canonical id "json_minify", v1.0.0).
Strips insignificant JSON whitespace (spaces, tabs, \n, \r that fall outside
string literals) without ever:
- reordering object keys,
- changing string content or escape sequences, or
- renormalizing number spelling (
1.0must stay1.0,1e10must stay1e10).
This is deliberately not implemented as parse-then-reserialize through
serde_json::Value. Re-serializing a Value would risk exactly the failure modes
above: serde_json’s number type does not remember whether 1.0 was spelled with a
trailing .0 or an exponent, and losing that spelling would change the byte identity
of prompts that providers may cache on. Key order is only preserved through
Value if the preserve_order feature is enabled crate-wide, which is a global,
easy-to-silently-break invariant; recovering that in a Value layer would be nice, but the
two problems above (numbers, and depending on a global feature flag for correctness)
are still true.
Instead, this transform:
- Validates the input by parsing it into a
serde_json::Valueand immediately discarding it. This enforces valid UTF-8 and valid JSON grammar (rejecting things like unterminated strings) without ever using the parsed value for output. - Performs a single lexical pass over the original bytes, tracking whether the
cursor is inside a string literal (so whitespace inside strings is never touched)
and whether the current byte is escaped (so an escaped quote
\"does not prematurely end the string).
Enums§
Constants§
- TRANSFORM_
ID - Canonical transform id, as registered with the pipeline.
- TRANSFORM_
VERSION - Semantic version of this transform’s output behavior.
Functions§
- minify_
json - Strips insignificant JSON whitespace from
input, preserving key order, string content/escapes, and number spelling exactly.