GuidesDuplicate Keys in JSON: Why They’re Dangerous
Duplicate Keys in JSON: Why They’re Dangerous
Updated 2026-07-23 · SparkJSON
When a JSON object defines the same key twice, behavior is undefined across parsers. JavaScript keeps the last value and drops earlier ones. SparkJSON flags duplicates so you catch accidental overwrites during formatting.
How duplicates appear
Merged configs, hand-written fixtures, and codegen bugs often emit `{ "id": 1, "id": 2 }`. The file may “look fine” in a text editor while silently losing the first `id`.
What to do
Rename keys, nest objects, or collapse values into an array. Re-validate after the structural fix. Don’t rely on which value “wins.”
FAQ
- Does RFC 8259 allow duplicate keys?
- The RFC notes that names should be unique; interoperability for duplicates is poor. Treat duplicates as defects.