From b1b38d8902c949e243cceba40c70ef7b3e604962 Mon Sep 17 00:00:00 2001 From: Mayank Basena <0mayankbasena@gmail.com> Date: Sat, 4 Jul 2026 16:48:50 +0530 Subject: [PATCH] gh-59598: Strip leading whitespace in JSONDecoder.raw_decode raw_decode currently ignores leading whitespace before JSON values, raising JSONDecodeError on strings like ' {"key": "value"}'. This is inconsistent with JSONDecoder.decode() which handles leading whitespace. Add s = s.lstrip() at the start of raw_decode to strip leading whitespace before decoding, matching the behavior of decode(). --- Lib/json/decoder.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py index 364e44d40cc3073..803a7ff0e68e815 100644 --- a/Lib/json/decoder.py +++ b/Lib/json/decoder.py @@ -370,6 +370,8 @@ def raw_decode(self, s, idx=0): have extraneous data at the end. """ + s = s.lstrip() + try: obj, end = self.scan_once(s, idx) except StopIteration as err: