Skip to content

Instantly share code, notes, and snippets.

@Velrok
Last active April 10, 2019 11:26
Show Gist options
  • Save Velrok/6f38b694ac19ba1a9434c40b3e652357 to your computer and use it in GitHub Desktop.
Save Velrok/6f38b694ac19ba1a9434c40b3e652357 to your computer and use it in GitHub Desktop.
cli to convert edn to json
#!/usr/bin/env inlein
'{:dependencies [[org.clojure/clojure "1.10.0"]
[cheshire "5.8.1"]]}
(require '[cheshire.core :as json])
(require '[clojure.edn :as edn])
(defn read-edn
[s]
(try
(edn/read-string s)
(catch java.lang.RuntimeException e
(binding [*out* *err*]
(println (format "ERROR: [%S] parsing: %s"
(.getMessage e)
s)))
nil)))
(run!
(fn [l]
(if l
(some->> l
read-edn
json/generate-string
println)
(System/exit 0)))
(repeatedly read-line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment