DEV Community

Clarice Bouwer
Clarice Bouwer

Posted on

3

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 (1)

Collapse
 
lenw profile image
Len Weincier

Check out transit

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