How to pretty print JSON to a file in Clojure?

You can use the built-in with-out-str function to capture anything written to the output buffer and store it as a string.

(with-out-str (clojure.data.json/pprint your-map-or-whatever))

Use the cheshire library found here and use the generate-string function with the pretty flag set to true

Example

;; generate some JSON with pretty formatting
(generate-string {:foo "bar" :baz {:eggplant [1 2 3]}} {:pretty true})
;; {
;;   "foo" : "bar",
;;   "baz" : {
;;     "eggplant" : [ 1, 2, 3 ]
;;   }
;; }