Transforming keys of a map in Clojure -


i'm working rest api represents account following json:

{ "username": "foo", "password": "bar", "emailid": "baz" } 

i have clojure function create account can called this:

(create-account :username "foo" :password "bar" :email "baz") 

what want map nice keys create-account takes funky ones rest api expects. current solution this:

(def clj->rest {:username :username                 :email :emailid})  (apply hash-map        (flatten (map                  (fn [[k v]] [(or (clj->rest k) k) v])                  args)))  ;; args arguments create-account, above 

is there more idiomatic way accomplish this?

(clojure.set/rename-keys args clj->rest) 

... mimics solution, producing ...

{:emailid "baz", :username "foo", :password "bar"} 

i take you've worked out how change required json.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -