Mailing List Archive

[issue5067] Error msg from using wrong quotes in JSON is unhelpful
New submission from Steven D'Aprano <steve@pearwood.info>:

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)

----------
messages: 80564
nosy: stevenjd
severity: normal
status: open
title: Error msg from using wrong quotes in JSON is unhelpful
versions: Python 2.6

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5067>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5067] Error msg from using wrong quotes in JSON is unhelpful [ In reply to ]
Changes by Steven D'Aprano <steve@pearwood.info>:


----------
components: +Library (Lib)
type: -> behavior

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5067>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5067] Error msg from using wrong quotes in JSON is unhelpful [ In reply to ]
Gabriel Genellina <gagsl-py2@yahoo.com.ar> added the comment:

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.

----------
nosy: +gagenellina

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5067>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5067] Error msg from using wrong quotes in JSON is unhelpful [ In reply to ]
Changes by Gabriel Genellina <gagsl-py2@yahoo.com.ar>:


----------
keywords: +patch
Added file: http://bugs.python.org/file12871/json-messages.diff

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5067>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com