How to beautifully print JSON to a file in Clojure?

I would like to store JSON content in files, but using a nice version.

To be clear, this is regular JSON:

{"b":2, "a":1}

This is a beautiful version:

{
    "b": 2,
    "a": 1
}

Is there a way in Clojure to achieve this?

+4
source share
1 answer

Use cheshire library here and use function generated string with 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 ]
;;   }
;; }
+7
source

Source: https://habr.com/ru/post/1538166/


All Articles