-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
More helpful error message in JSON decoder #113047
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
Conversation
While JavaScript typically parses the following example, it is not strictly valid JSON. But while the current Python error message `Expecting property name enclosed in double quotes` hints at a missing quote, the problem in fact is a trailing comma: ```js { "key": "value", } ```
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for filing this issue! I had a question but I believe @rhettinger may have thoughts here.
Lib/json/decoder.py
Outdated
@@ -161,7 +161,7 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook, | |||
return pairs, end + 1 | |||
elif nextchar != '"': | |||
raise JSONDecodeError( | |||
"Expecting property name enclosed in double quotes", s, end) | |||
"Expecting a property name enclosed in double quotes (no trailing comma allowed)", s, end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to not have this be handled in a dedicated case with a more specific error message? It kind of seems like we might be burying the lede with the current error message if the trailing comma is the issue.
It is not so simple.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
While JavaScript typically parses the following example, it is not strictly valid JSON. But while the current Python error message
Expecting property name enclosed in double quotes
hints at a missing quote, the problem in fact is a trailing comma:The new error message becomes:
Expecting a property name enclosed in double quotes (no trailing comma allowed)
I believe this trivial change does neither require a NEWS entry nor a separate issue, but I do not have experience if there are any tools that depend on the exact error message of the exception...