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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay