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

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay