Replacer function support for TOON encoding.
Provides transformation and filtering capabilities during encoding, similar to JSON.stringify's replacer parameter but with path tracking.
Replacer function support for TOON encoding. Provides transformation and filtering capabilities during encoding, similar to JSON.stringify's replacer parameter but with path tracking.
(apply-replacer root replacer)Applies a replacer function to a value and all its descendants.
The replacer is called for:
Parameters:
Returns: The transformed value.
Examples: ;; Remove password fields (apply-replacer data (fn [k v _] (when-not (= k "password") v)))
;; Transform string values to uppercase (apply-replacer data (fn [k v _] (if (string? v) (clojure.string/upper-case v) v)))
;; Add timestamp to root object (apply-replacer data (fn [k v path] (if (empty? path) (assoc v :timestamp (System/currentTimeMillis)) v)))
Applies a replacer function to a value and all its descendants.
The replacer is called for:
- The root value (with key="", path=[])
- Every map property (with the property name as key)
- Every vector element (with the string index as key: "0", "1", etc.)
Parameters:
- root: The normalized value to transform
- replacer: Function (fn [key value path] ...) that returns:
- The replacement value (will be normalized again)
- nil to omit the property/element (root cannot be omitted)
Returns:
The transformed value.
Examples:
;; Remove password fields
(apply-replacer data (fn [k v _] (when-not (= k "password") v)))
;; Transform string values to uppercase
(apply-replacer data (fn [k v _] (if (string? v) (clojure.string/upper-case v) v)))
;; Add timestamp to root object
(apply-replacer data (fn [k v path]
(if (empty? path)
(assoc v :timestamp (System/currentTimeMillis))
v)))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 |