[issue21451] Improve error messages for malformed JSON

2014-05-07 Thread Raymond Hettinger

New submission from Raymond Hettinger:

The error message for malformed JSON just tells you that the JSON is invalid, 
it doesn't say why (showing you which character bombed, what text is being 
read, what the pending openers are, or what allowable characters would have 
been expected).  In the absence of this information, it is very difficult to 
debug hand-rolled JSON.

   json.loads('sample_file.json') # students find this hard to debug

   json.loads('''[
  boys: 10,
  girls: 20,
 ]''')# hard to see trailing comma

   json.loads(['python', 'perl', 'ruby'])  # needs double quotes

   json.loads([[10, 20], [30, 40]]]) # unbalanced delimiters

--
messages: 218062
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Improve error messages for malformed JSON
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21451
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21451] Improve error messages for malformed JSON

2014-05-07 Thread R. David Murray

R. David Murray added the comment:

Python 3.4.0+ (3.4:d994d75cce95, May  6 2014, 21:37:02) 
[GCC 4.8.2] on linux
Type help, copyright, credits or license for more information.
 import json
 json.loads('''[
...   boys: 10,
...   girls: 20,
...  ]''')
Traceback (most recent call last):
   ...
ValueError: Expecting ',' delimiter: line 2 column 17 (char 18)
 json.loads(['python', 'perl', 'ruby'])
Traceback (most recent call last):
   ...
ValueError: Expecting value: line 1 column 2 (char 1)
 json.loads([[10, 20], [30, 40]]])
Traceback (most recent call last):
   ...
ValueError: Extra data: line 1 column 21 - line 1 column 22 (char 20 - 21)

See issue 16009 for when this was added. Can you improve these? (The first one 
looks odd...)  If so, you could reopen this.

--
nosy: +r.david.murray
resolution:  - duplicate
stage:  - resolved
status: open - closed
superseder:  - Json error messages could provide more information about the 
error
versions:  -Python 2.7, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21451
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21451] Improve error messages for malformed JSON

2014-05-07 Thread Raymond Hettinger

Raymond Hettinger added the comment:

What do you think about backporting the improved error messages?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21451
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue21451] Improve error messages for malformed JSON

2014-05-07 Thread R. David Murray

R. David Murray added the comment:

Hmm.  I guess I don't have any objection in principle.  It is hard to imagine 
why someone would depend on the exact format of the old low-information 
messages, though anything is possible.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue21451
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com