Data normalization for TOON encoding.
Converts Clojure data structures to JSON-compatible values:
Data normalization for TOON encoding. Converts Clojure data structures to JSON-compatible values: - Keywords → strings - Symbols → strings - Sets → vectors - Maps with keyword keys → maps with string keys - UUIDs → strings - Dates/Instants → ISO-8601 strings - NaN/Infinity → nil - Functions/vars → nil
(normalize-value value)(normalize-value value depth max-depth)Normalizes a Clojure value to a JSON-compatible representation.
Normalization rules:
Parameters:
Returns: JSON-compatible value (nil, boolean, number, string, vector, or map)
Throws: ex-info if max-depth is exceeded to prevent stack overflow
Normalizes a Clojure value to a JSON-compatible representation. Normalization rules: - nil → nil - Booleans → unchanged - Strings → unchanged - Numbers: - Finite → unchanged (with -0 → 0) - NaN, Infinity, -Infinity → nil - Keywords → strings (e.g., :foo → "foo", :user/id → "user/id") - Symbols → strings (e.g., 'foo → "foo") - UUIDs → strings - Dates/Instants → ISO-8601 strings - BigInt/BigDecimal → number or string (if out of safe range) - Sets → vectors (sorted for determinism) - Maps → maps with string keys (recursively normalized values) - Vectors/Lists → vectors (recursively normalized) - Functions, vars, undefined → nil Parameters: - value: Any Clojure value - depth: (optional) Current nesting depth (default: 0) - max-depth: (optional) Maximum nesting depth (default: 1000) Returns: JSON-compatible value (nil, boolean, number, string, vector, or map) Throws: ex-info if max-depth is exceeded to prevent stack overflow
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |