How to write formatted EDN to a file in Clojure

Clarice Bouwer - Feb 29 - - Dev Community

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
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .