Search code examples
data-structuresclojurehashmap

Convert hashmap to hash-string-map in Clojure


I have the following data structure:

 {:a {:x 1 :y 2} :b {:w 1 :z 2} :c {:m 1 :n 2}}

How can I transform that into a string-hash-map?

I want the following data structure:

{"a" {:x 1 :y 2} 1 {:w 1 :z 2} 2 "c" {:m 1 :n 2}}

Solution

  • (let [data {:a {:x 1 :y 2} :b {:w 1 :z 2} :c {:m 1 :n 2}}]
            (update-keys data name))
    => {"a" {:x 1, :y 2}, "b" {:w 1, :z 2}, "c" {:m 1, :n 2}}