Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cheshire lazy parsing lets some malformed JSON pass through #57

Open
rwilson opened this issue Mar 9, 2018 · 1 comment
Open

Cheshire lazy parsing lets some malformed JSON pass through #57

rwilson opened this issue Mar 9, 2018 · 1 comment

Comments

@rwilson
Copy link

rwilson commented Mar 9, 2018

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:

  1. Lazy parsing has some benefits, leave it and document for clarity.
  2. Always or optionally realize body to catch the exception

Thoughts?

@dco-lentz
Copy link

This was a puzzling behavior that i also had to track down. My opinion is that by default the library should not silently pass along invalid JSON until the lazy sequence is ultimately realized down the line, likely outside of whatever try/catch block one has put in place to handle decoding errors. Opt-in laziness would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants