Fork me on GitHub
#malli
<
2022-07-26
>
Yehonathan Sharvit06:07:36

I am surprised by how JSON transformer works

(m/decode :int "123" malli.transform/json-transformer) ;; => "123"
Why isn’t the string "123" converted to an integer? In the same way,
(m/decode [:map [:foo :int]] {:foo "123"} malli.transform/json-transformer) ;; => {:foo "123"}

vemv08:07:28

malli.transform/-json-decoders doesn't have a string->double thingy maybe you want to be looking at malli.transform/string-transformer instead?

Yehonathan Sharvit09:07:01

The distinction between json-decoders and string-decoders is not 100% clear to me

vemv09:07:49

My impression is that string-transformer is for parsing string-based values, and json-transformer for enriching values from already-parsed json with JVM/clj types (uuid, date, keyword etc) not present in json So it might make sense to compose string-transformer with json-transformer

Yehonathan Sharvit10:07:09

It makes sense to me also

Yehonathan Sharvit10:07:42

@U45T93RA6 Is there a transformer that keywordize map keys when the schema keys are keywords?

vemv10:07:48

let's move it 1:1

pppaul13:07:15

I have a list of keyseqs [[:parent :child1 :child2]...]that map in a human readable way into my schema, but when i do mu/get-in mu/update-in the mappings don't work. when i do subschemas the paths are sorta like [:parent 0 0 :child1 0 0 :child2] and :parent will have 10 different paths to the same :child1 and :child2. it seems a bit like a flip of a coin if i get the correct path or not. i've tried a few different ways of figuring out the correct one (smallest count). also the :in and :path are different, and i'm not sure what to use in mu/update-in. unfortunately i'm not in control of the schema (it's generated based off of json-schema). my next approach will involve recursive mu/find-in, but i'm wondering if anyone has run into a problem like this before, where conceptual indexing and real malli indexing have a significant mismatch and how to get to the correct spots in the schema to programmatically edit it (i'm adding custom properties)