Last active
March 27, 2020 18:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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