Skip to content

Instantly share code, notes, and snippets.

@matthewdowney
Last active March 27, 2020 18:49
Show Gist options
  • Save matthewdowney/172a831c044c437d05b3ffca0207fda4 to your computer and use it in GitHub Desktop.
Save matthewdowney/172a831c044c437d05b3ffca0207fda4 to your computer and use it in GitHub Desktop.
Boot CLI for converting EDN to JSON. E.g. $ cat ledger.edn | ./edn2json
#!/usr/bin/env boot
(set-env! :dependencies '[[org.clojure/data.json "0.2.6"]
[org.clojure/clojure "1.8.0"]])
(require '[boot.cli :refer [defclifn]])
(require '[clojure.java.io :as io])
(require '[clojure.data.json :as json])
(defclifn -main
[t transform VAL str "A literal function to transform each EDN element with before JSON-writing."]
(let [xf (eval (read-string (get *opts* :transform "identity")))]
(with-open [r (io/reader *in*)]
(->> (line-seq r)
(map (comp println json/write-str xf read-string))
(dorun)))))
;; To get this running, you need boot:
;; $ sudo bash -c "cd /usr/local/bin && curl -fsSLo boot https://github.com/boot-clj/boot-bin/releases/download/latest/boot.sh && chmod 755 boot"
;; Then you need this file saved as edn2json
;; $ chmod +x edn2json
;; $ echo "{:foo :bar}" | ./edn2json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment