           (recur nxt)))))
   (.print out \}))
 
-(defn- write-json-array [s ^PrintWriter out]
+(defn- write-array [s ^PrintWriter out]
   (.print out \[)
   (loop [x s]
     (when (seq x)

          (recur nxt)))))
  (.print out \]))

(defn- write-json-bignum [x ^PrintWriter out]
  (.print out (str x)))

(defn- write-json-plain [x ^PrintWriter out]
  (.print out x))

(defn- write-json-null [x ^PrintWriter out]
  (.print out "null"))

(defn- write-json-named [x out]
  (write-json-string (name x) out))

(defn- write-json-generic [x out]
  (if (.isArray (class x))
    (-write-json (seq x) out)
    (throw (Exception. (str "Don't know how to write JSON of " (class x))))))

(defn- write-json-ratio [x out]
  (-write-json (double x) out))

(extend nil JSONWriter
        {:-write-json write-json-null})
(extend clojure.lang.Named JSONWriter
        {:-write-json write-json-named})
(extend java.lang.Boolean JSONWriter
        {:-write-json write-json-plain})
(extend java.lang.Number JSONWriter
        {:-write-json write-json-plain})
(extend java.math.BigInteger JSONWriter
        {:-write-json write-json-bignum})
(extend java.math.BigDecimal JSONWriter
        {:-write-json write-json-bignum})
(extend clojure.lang.Ratio JSONWriter
        {:-write-json write-json-ratio})
(extend java.lang.CharSequence JSONWriter
        {:-write-json write-json-string})
(extend java.util.Map JSONWriter
        {:-write-json write-json-object})
(extend java.util.Collection JSONWriter
        {:-write-json write-json-array})
(extend clojure.lang.ISeq JSONWriter
        {:-write-json write-json-array})
(extend java.lang.Object JSONWriter
        {:-write-json write-json-generic})

(defn write-json
  "Write JSON-formatted output to a java.io.Writer.
   Options are key-value pairs, valid options are:

    :escape-unicode false
        to turn off \\uXXXX escapes of Unicode characters

    :escape-slash false
        to turn of escaping / as \\/"
  [x ^Writer writer & options]
  (let [{:keys [escape-unicode escape-slash]
         :or {escape-unicode true

  (-write-json [object out]
    "Print object to PrintWriter out as JSON"))

(defn- write-string [^CharSequence s ^PrintWriter out]
  (let [sb (StringBuilder. (count s))]
    (.append sb \")
    (dotimes [i (count s)]
