From 7d8353401ad0943a00423cb4f3e7d71a4b6a162f Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 10 Aug 2017 19:05:57 -0400 Subject: [PATCH] Adding JSONTokener.back() just before throwing JSONException This forces JSONTokener.syntaxError(..) to point to the last character of the duplicate key. --- JSONObject.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/JSONObject.java b/JSONObject.java index 9d5fc87..28f401e 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -232,12 +232,13 @@ public class JSONObject { throw x.syntaxError("Expected a ':' after a key"); } - // Replace: this.putOnce(key, x.nextValue()); // Use syntaxError(..) to include error location if (key != null) { // Check if key exists if (this.opt(key) != null) { + // back one token to point to the last key character + x.back(); throw x.syntaxError("Duplicate key \"" + key + "\""); } // Only add value if non-null