Skip to content

Commit

Permalink
Handle quotes in JSON keys correctly; refs #98
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Sierra committed Nov 26, 2010
1 parent a579d18 commit d6f6ccf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions modules/json/src/main/clojure/clojure/contrib/json.clj
Expand Up @@ -238,9 +238,7 @@
(let [[k v] (first x)]
(when (nil? k)
(throw (Exception. "JSON object keys cannot be nil/null")))
(.print out \")
(.print out (as-str k))
(.print out \")
(write-json-string (as-str k) out)
(.print out \:)
(write-json v out))
(let [nxt (next x)]
Expand Down
3 changes: 3 additions & 0 deletions modules/json/src/test/clojure/clojure/contrib/test_json.clj
Expand Up @@ -185,6 +185,9 @@
(deftest can-accept-eof
(is (= ::eof (read-json "" true false ::eof))))

(deftest characters-in-map-keys-are-escaped
(is (= (json-str {"\"" 42}) "{\"\\\"\":42}")))

;;; Pretty-printer

(deftest pretty-printing
Expand Down

0 comments on commit d6f6ccf

Please sign in to comment.