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

Clarice Bouwer @cbillowes

About: Curious programmer sharing byte-sized knowledge on dev.to. Passionate about Git, GCP, TypeScript, Next.js, and DevTools. Enjoys collaborating with others and leading by example.

Location:
Mauritius
Joined:
May 30, 2018

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

Publish Date: Jun 26 '23
0 0

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.

Comments 0 total

    Add comment