Fork me on GitHub
#malli
<
2022-07-15
>
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))

valtteri11:07:43

There's a built-in strip-extra-keys-transformer for value transformation https://github.com/metosin/malli#value-transformation

1
Ferdinand Beyer11:07:05

Amazing, thanks! Missed that one 😊

valtteri11:07:22

No problem 🙂