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
Post a Comment