borkdude / jet

CLI to transform between JSON, EDN, YAML and Transit using Clojure

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sort keys in a map

agzam opened this issue · comments

I'm sorry, I can't figure this out. If you give me some pointers how to do this, I will send a PR for documentation update. I'm trying this and it's not working:

echo '{:b 2 :c 3 :a 1}' | jet --query '(into (sorted-map) #jet/lit)'

I'm sure at least a few people would find this functionality useful. Thanks!

Well, where jet cannot fly, babashka can plow through:

echo '{:b 2 :c 3 :a 1}' | bb '(into (sorted-map) *input*)'

But I'm still curious, if you can do this with jet

sorted-map simply isn't available in the query language. I'm considering of just adding -e to jet so you can do the same as with bb in your last comment, since the query language is a bit weird sometimes.

Alright. That sounds exciting. Thank you for building such amazing set of tools. Everyone loves jet and everyone loves babashka. On that note I am going to close this issue.

Just in case anyone else stumbles across this… now that jet has the --function | -f option, one can do something like this:

echo '{:b 2 :c 3 :a 1}' | jet -f '#(into (sorted-map) %)'

And here’s what I came up with to do the same but recursively:

echo '{:b 2 :c 3 :a 1 :q {:z 4 :y 6 :x 5}}' | jet -f '(fn [v] (clojure.walk/postwalk #(if (map? %) (into (sorted-map) %) %) v))'