This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2009年01月26日 06:24 by steven.daprano, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| json-messages.diff | ggenellina, 2009年01月27日 01:06 | |||
| json-messages-2.patch | serhiy.storchaka, 2012年06月15日 09:30 | review | ||
| Messages (12) | |||
|---|---|---|---|
| msg80564 - (view) | Author: Steven D'Aprano (steven.daprano) * (Python committer) | Date: 2009年01月26日 06:24 | |
Using the wrong sort of quotes in json gives unhelpful error messages:
>>> json.loads("{'test':'test'}")
Traceback (most recent call last):
...
ValueError: Expecting property name: line 1 column 1 (char 1)
Unless you know that strings in JSON must be delimited with
double-quotes and not single (a very surprising fact to those used to
Python) this error message is perplexing. I suggest something like:
Single-quoted strings are invalid property names: line 1 column 1
(char 1)
or
Parse error, invalid char: line 1, column 1 (char 1)
|
|||
| msg80604 - (view) | Author: Gabriel Genellina (ggenellina) | Date: 2009年01月27日 01:05 | |
This patch provides a better error message for this case::
json.loads("""{'test': "test"}""")
but still doesn't help in this one::
json.loads("""{"test": 'test'}""")
'test' looks like garbage to JSON (it *is* garbage!), exactly the same
as::
json.loads("""{"test": @?&%%}""")
so it's hard to provide a better message when the parser expects a
generic object.
|
|||
| msg82949 - (view) | Author: Cherniavsky Beni (cben) * | Date: 2009年03月01日 00:52 | |
Perhaps it should not be an error at all? The default should probably stay strict to the spec, but IMHO the module should provide an optional lenient parsing mode that also accepts single quotes. Why support single quotes and not any other imaginable deviation from the spec? Because single quotes are the only way (AFAIK) in which Python's repr() produces invalid JSON (from JSONable combinations of types). |
|||
| msg82951 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2009年03月01日 01:48 | |
+1 on Steven's request for a better error message.
+1 on Beni's request for looser input requirements for better
interoperability with Python's repr. OTOH, I've never found it hard to
write: s.replace("'", '"').
|
|||
| msg82970 - (view) | Author: Bob Ippolito (bob.ippolito) * (Python committer) | Date: 2009年03月01日 18:00 | |
I don't really want to see looser input requirements, making a JSON parser that is compatible with a subset of Python repr output isn't a design goal of mine. This is absolutely false: "Because single quotes are the only way (AFAIK) in which Python's repr() produces invalid JSON (from JSONable combinations of types)." >>> repr(object) "<type 'object'>" If you don't know JSON, I'm not sure throwing random input at the JSON parser is going to help you. Is that how you learned XML? There's plenty of info in the JSON documentation and a link to json.org if you need help. |
|||
| msg82971 - (view) | Author: Bob Ippolito (bob.ippolito) * (Python committer) | Date: 2009年03月01日 18:04 | |
Er, sorry, missed "(from JSONable combinations of types)". It's early.
Anyway, I can change the error message, but I will not make it special-
case single quotes for its own error message. I will have to think about
what the message could say instead. Note that the same sort of person who
throws random input at parsers might even expect {test: 'test'} to work
since that is valid JavaScript but not valid JSON.
|
|||
| msg162878 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年06月15日 09:30 | |
Patch adapted for Python 3.3. Consistently changed messages in C code, docs and docstrings. |
|||
| msg163581 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2012年06月23日 11:25 | |
Any chance to commit the patch today and to get this feature in Python 3.3? |
|||
| msg163841 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2012年06月24日 20:16 | |
I would say this is a bugfix, so it can go in after the beta. Georg? |
|||
| msg163845 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2012年06月24日 20:21 | |
Agreed. |
|||
| msg164304 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年06月29日 00:03 | |
New changeset 9854520c8200 by Antoine Pitrou in branch '3.2': Issue #5067: improve some json error messages. http://hg.python.org/cpython/rev/9854520c8200 New changeset 7523ab4e6e06 by Antoine Pitrou in branch 'default': Issue #5067: improve some json error messages. http://hg.python.org/cpython/rev/7523ab4e6e06 New changeset 7762816e3fcd by Antoine Pitrou in branch '2.7': Issue #5067: improve some json error messages. http://hg.python.org/cpython/rev/7762816e3fcd |
|||
| msg164305 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2012年06月29日 00:04 | |
Committed now. Thanks Serhiy for the patch! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:44 | admin | set | github: 49317 |
| 2012年06月29日 00:04:19 | pitrou | set | status: open -> closed resolution: fixed messages: + msg164305 stage: patch review -> resolved |
| 2012年06月29日 00:03:51 | python-dev | set | nosy:
+ python-dev messages: + msg164304 |
| 2012年06月24日 20:24:56 | ezio.melotti | set | nosy:
+ ezio.melotti |
| 2012年06月24日 20:21:10 | georg.brandl | set | messages: + msg163845 |
| 2012年06月24日 20:16:25 | pitrou | set | nosy:
+ pitrou, georg.brandl messages: + msg163841 assignee: bob.ippolito -> components: - Documentation stage: patch review |
| 2012年06月23日 11:25:57 | serhiy.storchaka | set | messages: + msg163581 |
| 2012年06月15日 09:30:47 | serhiy.storchaka | set | files:
+ json-messages-2.patch versions: + Python 2.7, Python 3.2, Python 3.3, - Python 2.6 nosy: + serhiy.storchaka messages: + msg162878 components: + Documentation |
| 2009年03月01日 18:04:00 | bob.ippolito | set | messages: + msg82971 |
| 2009年03月01日 18:00:56 | bob.ippolito | set | messages: + msg82970 |
| 2009年03月01日 01:48:17 | rhettinger | set | assignee: bob.ippolito messages: + msg82951 nosy: + bob.ippolito, rhettinger |
| 2009年03月01日 00:52:46 | cben | set | nosy:
+ cben messages: + msg82949 |
| 2009年01月27日 01:06:13 | ggenellina | set | files:
+ json-messages.diff keywords: + patch |
| 2009年01月27日 01:05:49 | ggenellina | set | nosy:
+ ggenellina messages: + msg80604 |
| 2009年01月26日 12:45:00 | steven.daprano | set | type: behavior components: + Library (Lib) |
| 2009年01月26日 06:24:32 | steven.daprano | create | |