-
-
Save jcromartie/3872b7bfd382ef706bd9 to your computer and use it in GitHub Desktop.
This file contains 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
(defn json-seq | |
[xs] | |
(apply str (interpose "," (map json-str xs)))) | |
(defn json-composite | |
[l r xs] | |
(str l (json-seq xs) r)) | |
(defmulti json-str class) | |
(defmethod json-str String [x] | |
(pr-str x)) | |
(defmethod json-str clojure.lang.APersistentMap [x] | |
(json-composite "{" "}" x)) | |
(defmethod json-str clojure.lang.APersistentVector [x] | |
(json-composite "[" "]" x)) | |
(defmethod json-str java.lang.Number [n] | |
(pr-str n)) | |
(defmethod json-str clojure.lang.Named [x] | |
(json-str (name x))) | |
(defmethod json-str clojure.lang.MapEntry [x] | |
(str (json-str (key x)) ":" (json-str (val x)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment