Specifically, when the malformed JSON is in an array.
It's easily demonstrated in a repl:
user> (def bad-json (cheshire.core/parse-string "[{\"foo\": 1 2}]"))
#'user/bad-json
user> (type bad-json)
clojure.lang.LazySeq
user> (first bad-json)
JsonParseException Unexpected character ('2' (code 50)): was expecting comma to separate Object entries
at [Source: (StringReader); line: 1, column: 13] com.fasterxml.jackson.core.JsonParser._constructError (JsonParser.java:1798)
The JsonParseException isn't thrown until the lazy sequence is realized, which may not be until subsequent middleware or an endpoint.
Options could be:
- Lazy parsing has some benefits, leave it and document for clarity.
- Always or optionally realize body to catch the exception
Thoughts?
Specifically, when the malformed JSON is in an array.
It's easily demonstrated in a repl:
The
JsonParseExceptionisn't thrown until the lazy sequence is realized, which may not be until subsequent middleware or an endpoint.Options could be:
Thoughts?