Duplicate keys in a JSON object
The same key appears twice. The JSON specification does not forbid this, and it does not define which value wins — so every parser in this registry accepts it, and most keep the last occurrence.
The input
{"a": 1, "a": 2}{"a": 2}How to fix it
There is no parse error to fix; you have to detect it yourself. Use a parser hook that inspects raw pairs — Python's `object_pairs_hook`, Go's `json.Decoder` with `DisallowUnknownFields` plus a custom unmarshaller, or a linter in CI.
This is the most dangerous entry in the registry precisely because nothing errors. A config file with a duplicated key silently uses one of the two values, and which one depends on the parser. Merged config fragments and hand-edited files are where it bites.
What each parser reports
Every message below was captured by running this exact input through the parser named. 0 of 21 parsers rejected it; 21 accepted it.
| Parser | Exact message |
|---|---|
| CPython json.loads CPython 3.12.3 | accepted — no error |
| encoding/json Unmarshal Go go1.22.2 | accepted — no error |
| Gson Java 21.0.12 | accepted — no error |
| Gson JsonParser (lenient off) Java 21.0.12 | accepted — no error |
| hjson Node.js 22.22.2 | accepted — no error |
| Jackson ObjectMapper Java 21.0.12 | accepted — no error |
| JavaScriptCore JSON.parse JavaScriptCore (Bun 1.4.1) | accepted — no error |
| json-bigint Node.js 22.22.2 | accepted — no error |
| JSON5 Node.js 22.22.2 | accepted — no error |
| JSON::PP Perl 5.038002 | accepted — no error |
| json_decode PHP 8.3.6 | accepted — no error |
| Newtonsoft.Json JsonConvert Newtonsoft.Json 13.0.3 on .NET 8.0.30 | accepted — no error |
| Newtonsoft.Json JsonTextReader Newtonsoft.Json 13.0.3 on .NET 8.0.30 | accepted — no error |
| orjson CPython 3.12.3 | accepted — no error |
| Ruby JSON.parse Ruby 3.2.3 | accepted — no error |
| serde_json::from_str Rust (serde_json 1.x) | accepted — no error |
| SpiderMonkey JSON.parse SpiderMonkey 115 | accepted — no error |
| System.Text.Json Deserialize .NET 8.0.30 | accepted — no error |
| System.Text.Json JsonDocument .NET 8.0.30 | accepted — no error |
| ujson CPython 3.12.3 | accepted — no error |
| V8 JSON.parse Node.js 22.22.2 | accepted — no error |
What the specification says
The exact sections that govern this error. Descriptions are our paraphrase; follow the links for the normative text.
| Body | Section |
|---|---|
| IETF | An object is curly brackets around zero or more members. A name is a string, a single colon separates name from value, and a single comma separates a value from a following name. |
| Ecma International | Gives the object grammar and states that the syntax does not require name strings to be unique and assigns no significance to member ordering. |
Other errors in this category
Integer too large for a JSON parser's number type
JSON's grammar permits arbitrary-precision numbers, but most parsers map them onto an IEEE 754 double, which holds integers exactl…