Welcome! Please see the About page for a little more info on how this works.

0 votes
in data.json by
retagged by

Calling (clojure.data.json/read-str (String. (byte-array [0]))) produces a very opaque error message (No matching clause: 0). I would like to provide a more useful message in the case of bad user-supplied data.

The current next-token implementation is:

(defn- next-token [^PushbackReader stream]
  (loop [c (.read stream)]
    (if (< 32 c)
      (int c)
      (codepoint-case (int c)
        :whitespace (recur (.read stream))
        -1 -1))))

Changing the last line -1 -1 to (int c) results in much more helpful messages:
(clojure.data.json/read-str (String. (byte-array [0]))) -> JSON error (unexpected character): \0
(clojure.data.json/read-str (String. (byte-array [123 0]))) -> JSON error (non-string key in object), found \0, expected "

1 Answer

0 votes
by
selected by
 
Best answer

Logged as https://clojure.atlassian.net/browse/DJSON-56

Importantly, we need to check this doesn't hurt performance.

...