DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on

How to write formatted EDN to a file in Clojure

You could be generating a config file, constructing a data file or downloading/extracting data from a data source. Sometimes, it needs to be human readable to make sense of it.

(spit "file.txt" (with-out-str (clojure.pprint data)))
Enter fullscreen mode Exit fullscreen mode
(with-open [wr (clojure.java.io/writer "file.edn")]
  (.write wr (with-out-str (clojure.pprint/pprint data))))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)