diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-28 23:59:54 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-06-28 23:59:54 (GMT) |
commit | 802d669044b14ae535e0136c6a9949a1725b7e14 (patch) | |
tree | 79dd128aa2e8a63906eac4a1e254cb5019949a89 /Lib/json | |
parent | 3a3dc17fc9a934682dda76188b367ec261905520 (diff) | |
parent | 2d24e94bbef97913b5fc434f991fa429f1533557 (diff) | |
download | cpython-802d669044b14ae535e0136c6a9949a1725b7e14.zip cpython-802d669044b14ae535e0136c6a9949a1725b7e14.tar.gz cpython-802d669044b14ae535e0136c6a9949a1725b7e14.tar.bz2 |
Issue #5067: improve some json error messages.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Lib/json')
-rw-r--r-- | Lib/json/__init__.py | 2 | ||||
-rw-r--r-- | Lib/json/decoder.py | 12 | ||||
-rw-r--r-- | Lib/json/tool.py | 2 |
3 files changed, 9 insertions, 7 deletions
diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py index ba2bc1d..725b5cd 100644 --- a/Lib/json/__init__.py +++ b/Lib/json/__init__.py @@ -97,7 +97,7 @@ Using json.tool from the shell to validate and pretty-print:: "json": "obj" } $ echo '{ 1.2:3.4}' | python -m json.tool - Expecting property name: line 1 column 2 (char 2) + Expecting property name enclosed in double quotes: line 1 column 2 (char 2) """ __version__ = '2.0.9' __all__ = [ diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py index e7c0539..07fd696 100644 --- a/Lib/json/decoder.py +++ b/Lib/json/decoder.py @@ -172,7 +172,8 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook, pairs = object_hook(pairs) return pairs, end + 1 elif nextchar != '"': - raise ValueError(errmsg("Expecting property name", s, end)) + raise ValueError(errmsg( + "Expecting property name enclosed in double quotes", s, end)) end += 1 while True: key, end = scanstring(s, end, strict) @@ -182,7 +183,7 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook, if s[end:end + 1] != ':': end = _w(s, end).end() if s[end:end + 1] != ':': - raise ValueError(errmsg("Expecting : delimiter", s, end)) + raise ValueError(errmsg("Expecting ':' delimiter", s, end)) end += 1 try: @@ -210,12 +211,13 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook, if nextchar == '}': break elif nextchar != ',': - raise ValueError(errmsg("Expecting , delimiter", s, end - 1)) + raise ValueError(errmsg("Expecting ',' delimiter", s, end - 1)) end = _w(s, end).end() nextchar = s[end:end + 1] end += 1 if nextchar != '"': - raise ValueError(errmsg("Expecting property name", s, end - 1)) + raise ValueError(errmsg( + "Expecting property name enclosed in double quotes", s, end - 1)) if object_pairs_hook is not None: result = object_pairs_hook(pairs) return result, end @@ -249,7 +251,7 @@ def JSONArray(s_and_end, scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR): if nextchar == ']': break elif nextchar != ',': - raise ValueError(errmsg("Expecting , delimiter", s, end)) + raise ValueError(errmsg("Expecting ',' delimiter", s, end)) try: if s[end] in _ws: end += 1 diff --git a/Lib/json/tool.py b/Lib/json/tool.py index 6d6558a..1adea31 100644 --- a/Lib/json/tool.py +++ b/Lib/json/tool.py @@ -7,7 +7,7 @@ Usage:: "json": "obj" } $ echo '{ 1.2:3.4}' | python -m json.tool - Expecting property name: line 1 column 2 (char 2) + Expecting property name enclosed in double quotes: line 1 column 2 (char 2) """ import sys |