malli

Joel 2025-11-21T18:31:53.417939Z

Is there a key-transformer, that even if the schema shows the key as a string, it’ll keyword it anyway?

(mt/key-transformer {:decode keyword})
My code doesn’t seem to get the change to change keys to strings before stripping extra keys. Does this have to be a decode instead?
(mt/transformer (mt/key-transformer {:encode name})
                mt/strip-extra-keys-transformer)

Joel 2025-12-04T04:03:08.459019Z

@joel.kaasinen I’m wondering if I’m going about this correctly, I have a timestamp for some reason stored as a string

["timestamp" {:decode/string malli.transform/-string->long :encode/string str} :string]
I wan to work with it as a long, the above works, but maybe a cleaner way?

Joel 2025-12-04T04:03:28.883779Z

like having a :timestamp type or somesuch.

opqdonut 2025-12-04T06:36:49.969629Z

yeah if you want to be a bit more structured about it you could either: • A) add :timestamp [:string {:decode/string ... :encode/string ...}] to your registry • B) add :timestamp :string to your registry ◦ and add a (transformer {:name :timestamp-trans :decoders {:timestamp ...} :encoders {:timestamp ...}}) to your transformer pipeline (in addition or instead of string-transformer)

1
opqdonut 2025-12-04T06:38:12.156289Z

there's one more way:

(def Timestamp [:string {:decode/string ... :encode/string ...}])

[:map ["timestamp" Timestamp]]

opqdonut 2025-11-25T13:18:03.694909Z

I'm having a hard time following your question. Could you give some examples of what's happening now and what you would want to happen? Meanwhile, this might help: • mt/strip-extra-keys-transformer always works in the :enter phase of transforming • mt/key-transformer works in the :leave phase when encoding, :enter when decoding • This means that when encoding, strip-extra-keys always runs before key-transformer • ... and when decoding, you can choose the order

opqdonut 2025-11-25T13:23:51.336989Z

Maybe this is what you want?

(m/decode [:map ["foo1" :string]]
          {"foo" "x" "bar" "y"}
          (mt/transformer (mt/key-transformer {:decode #(str % "1")})
                          mt/strip-extra-keys-transformer))
; ==> {"foo1" "x"}

opqdonut 2025-11-25T13:24:25.429209Z

"foo" gets decoded to "foo1", which then doesn't get stripped by strip-extra-keys-transformer

Joel 2025-11-25T13:58:01.739289Z

Thanks, knowing that it can work on decoding helps.