Duplicate Keys in JSON
The JSON specification does not explicitly forbid duplicate keys, but it strongly discourages them. When duplicate keys exist, most parsers silently keep only the last value and discard earlier ones. This leads to data loss that is extremely hard to debug.
Why It Matters
Data is silently lost without any error or warning. If you have two properties named 'email', only the last one is kept. This can cause security issues, configuration bugs, and data corruption that goes unnoticed for a long time.
Common Causes
- Merging two JSON objects or config layers that both define the same key.
- Copy-pasting a property to create a new one and forgetting to rename the key.
- Generating JSON programmatically from a source that produces the same field name twice.
Code Examples
{
"name": "John",
"email": "john@work.com",
"age": 30,
"email": "john@personal.com"
}{
"name": "John",
"workEmail": "john@work.com",
"personalEmail": "john@personal.com",
"age": 30
}How to Fix
- 1Search for duplicate key names in your JSON document.
- 2Rename duplicate keys to be unique and descriptive.
- 3If you need multiple values for a concept, use an array instead.
- 4Use a JSON linter that warns about duplicate keys, since most parsers silently accept them.
Frequently Asked Questions
Does the JSON spec forbid duplicate keys?
Which value wins when a key is duplicated?
How do I detect duplicate keys if parsers stay silent?
Check Your JSON Now
Our JSON validator detects this error automatically and shows the exact line and column.
Open JSON ValidatorCloudways · Managed Cloud Hosting
Fix this JSON error, then deploy on Cloudways managed cloud (AWS, GCP, DigitalOcean).
Free 3-day trial · 30% off 3 months + free site migration with code MIGRATE303
Related JSON Errors
Unquoted Property Keys in JSON
JSON requires every property name wrapped in double quotes, so bare keys fail. Learn how to fix unquoted key errors when converting JavaScript objects.
Missing Comma Between Properties
Fix the missing comma error in JSON the right way. Every key-value pair and array element must be separated by a comma, and our examples show where.
Unexpected Token in JSON
Fix the unexpected token error in JSON fast. See why parsers fail on trailing commas, single quotes, unquoted keys, and comments, with clear examples.