DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on

Cheat: read edn file, replace values and return condensed map

You can see how to replace nested values in Clojure in this post.

This code will

  • read an edn file
  • convert the edn from string to a Clojure data structure
  • get the first item in the vector
  • recursively replace values inside that map
  • convert it back to a map
  • print the result on one line to use as a condensed map
(-> (slurp "path/to/file.edn")
    clojure.edn/read-string
    first
    (replace-values :something "something")
    (replace-values :else "else")
    (into {})
    prn)
Enter fullscreen mode Exit fullscreen mode

This is pretty useful if you are creating files with a bunch of test data in it.

Top comments (0)