Skip to content

Instantly share code, notes, and snippets.

@algal
Created March 29, 2016 18:25
Show Gist options
  • Save algal/9deedc9184111eb3afe820a2032238ba to your computer and use it in GitHub Desktop.
Save algal/9deedc9184111eb3afe820a2032238ba to your computer and use it in GitHub Desktop.
Quick edn-to-json, with basic handling of date and uuid types
#!/usr/bin/env boot
;; needs boot-clj
;; converts edn to json,
;; - taking #inst to strings of ISO8601 timestamps
;; - taking #uuid to strings
(set-env! :dependencies '[[org.clojure/data.json "0.2.6"]])
(require '[clojure.data.json :as json])
(require '[clojure.edn :as edn])
(defn run [in out]
(let [inst->iso-string (fn [moment]
(let [s (pr-str moment)]
(subs s 7 (- (.length s) 1))))
value-fn (fn [k v]
(condp instance? v
java.util.Date (inst->iso-string v)
java.util.UUID (str v)
v))
data (edn/read in)]
(json/write data out :value-fn value-fn)))
(defn -main [& args]
(run *in* *out*))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment