diff -r aa77f7eb2bf1 Doc/library/json.rst --- a/Doc/library/json.rst Mon Feb 18 13:33:37 2013 +0200 +++ b/Doc/library/json.rst Mon Feb 18 18:43:00 2013 +0200 @@ -101,7 +101,7 @@ "json": "obj" } $ echo '{1.2:3.4}' | python -mjson.tool - Expecting property name enclosed in double quotes: line 1 column 1 (char 1) + Expecting property name enclosed in double quotes: line 1 column 2 (char 1) .. highlight:: python3 diff -r aa77f7eb2bf1 Lib/json/__init__.py --- a/Lib/json/__init__.py Mon Feb 18 13:33:37 2013 +0200 +++ b/Lib/json/__init__.py Mon Feb 18 18:43:00 2013 +0200 @@ -96,7 +96,7 @@ "json": "obj" } $ echo '{ 1.2:3.4}' | python -m json.tool - Expecting property name enclosed in double quotes: line 1 column 2 (char 2) + Expecting property name enclosed in double quotes: line 1 column 3 (char 2) """ __version__ = '2.0.9' __all__ = [ diff -r aa77f7eb2bf1 Lib/json/decoder.py --- a/Lib/json/decoder.py Mon Feb 18 13:33:37 2013 +0200 +++ b/Lib/json/decoder.py Mon Feb 18 18:43:00 2013 +0200 @@ -24,7 +24,7 @@ newline = '\n' lineno = doc.count(newline, 0, pos) + 1 if lineno == 1: - colno = pos + colno = pos + 1 else: colno = pos - doc.rindex(newline, 0, pos) return lineno, colno diff -r aa77f7eb2bf1 Lib/json/tool.py --- a/Lib/json/tool.py Mon Feb 18 13:33:37 2013 +0200 +++ b/Lib/json/tool.py Mon Feb 18 18:43:00 2013 +0200 @@ -7,7 +7,7 @@ "json": "obj" } $ echo '{ 1.2:3.4}' | python -m json.tool - Expecting property name enclosed in double quotes: line 1 column 2 (char 2) + Expecting property name enclosed in double quotes: line 1 column 3 (char 2) """ import sys diff -r aa77f7eb2bf1 Lib/test/json_tests/test_fail.py --- a/Lib/test/json_tests/test_fail.py Mon Feb 18 13:33:37 2013 +0200 +++ b/Lib/test/json_tests/test_fail.py Mon Feb 18 18:43:00 2013 +0200 @@ -125,8 +125,8 @@ ] for data, msg, idx in test_cases: self.assertRaisesRegex(ValueError, - r'^{0}: line 1 column {1} \(char {1}\)'.format( - re.escape(msg), idx), + r'^{0}: line 1 column {1} \(char {2}\)'.format( + re.escape(msg), idx + 1, idx), self.loads, data) def test_unexpected_data(self): @@ -155,8 +155,8 @@ ] for data, msg, idx in test_cases: self.assertRaisesRegex(ValueError, - r'^{0}: line 1 column {1} \(char {1}\)'.format( - re.escape(msg), idx), + r'^{0}: line 1 column {1} \(char {2}\)'.format( + re.escape(msg), idx + 1, idx), self.loads, data) def test_extra_data(self): @@ -173,10 +173,22 @@ for data, msg, idx in test_cases: self.assertRaisesRegex(ValueError, r'^{0}: line 1 column {1} - line 1 column {2}' - r' \(char {1} - {2}\)'.format( - re.escape(msg), idx, len(data)), + r' \(char {3} - {4}\)'.format( + re.escape(msg), idx + 1, len(data) + 1, idx, len(data)), self.loads, data) + def test_multiline(self): + test_cases = [ + ('!', 'Expecting value', 1, 1, 0), + (' !', 'Expecting value', 1, 2, 1), + ('\n!', 'Expecting value', 2, 1, 1), + ('\n \n\n !', 'Expecting value', 4, 6, 10), + ] + for data, msg, line, col, idx in test_cases: + self.assertRaisesRegex(ValueError, + r'^{0}: line {1} column {2} \(char {3}\)$'.format( + re.escape(msg), line, col, idx), + self.loads, data) class TestPyFail(TestFail, PyTest): pass class TestCFail(TestFail, CTest): pass diff -r aa77f7eb2bf1 Misc/NEWS --- a/Misc/NEWS Mon Feb 18 13:33:37 2013 +0200 +++ b/Misc/NEWS Mon Feb 18 18:43:00 2013 +0200 @@ -257,6 +257,9 @@ Library ------- +- Issue #17225: JSON decoder now counts columns in the first line starting + with 1, as in other lines. + - Issue #13153: Tkinter functions now raise TclError instead of ValueError when a string argument contains non-BMP character.