Fork me on GitHub
Ferdinand Beyer11:07:14

Is there a built-in way in Malli to strip away map keys that are not in the schema? Let’s say I have an open map schema like this:

[:map [:person/first-name string?]
      [:person/last-name string?]]
And a compliant value with an extra key:
{:person/first-name "Cosmo"
 :person/last-name "Kramer"
 :person/likes #{:fruit}}
I’d like to “sanitise” this data and only keep specified keys, recursively.

Ferdinand Beyer11:07:13

Thanks for acting as a sound stage. I found a simple way that can easily extended for recursive application:

(require '[malli.util :as mu])

(select-keys data (mu/keys schema))


There's a built-in strip-extra-keys-transformer for value transformation

Ferdinand Beyer11:07:05

Amazing, thanks! Missed that one 😊


No problem 🙂