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

0 votes
in data.json by

Handling of numeric literals doesn't perform according to the JSON spec.

Example:

(require '[clojure.data.json :as json]) (json/read-str "123abc")

Returns the number 1232. According to the spec, this should actually be an invalid literal and throw an exception:

!http://json.org/number.gif!

3 Answers

0 votes
by

Comment made by: alex+import

(I assume there's a typo in the description - 123 is returned, not 1232)

It's not just literal values, non-whitespace at the end of any input is silently ignored and should be rejected:

(json/read-str "{}xxx") => {} (json/read-str "[]yyy") => [] (json/read-str "\"\"zzz") => ""

NB This behaviour agrees with the docstring ("Reads a single item of JSON data from ...").

0 votes
by
Reference: https://clojure.atlassian.net/browse/DJSON-21 (reported by alex+import)
0 votes
by

This does throw an exception in 2.4.0, even though the JIRA issue has not been updated. Other data types still allow extra input, as described by the docstring.

by
I think we left that open as we're still deciding what to do about the broader question of "parse whole input" vs "parse json values from streams".
...