Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created February 2, 2012 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcromartie/3872b7bfd382ef706bd9 to your computer and use it in GitHub Desktop.
Save jcromartie/3872b7bfd382ef706bd9 to your computer and use it in GitHub Desktop.
(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