</>
ValidateHTML

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

Invalid JSON
{
  "name": "John",
  "email": "john@work.com",
  "age": 30,
  "email": "john@personal.com"
}
Valid JSON
{
  "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?
Not strictly. RFC 8259 says names within an object should be unique and warns that behavior is unpredictable when they are not. Most parsers accept the input and keep only the last value, so it is legal but unsafe.
Which value wins when a key is duplicated?
In nearly every mainstream parser, including JavaScript's JSON.parse, the last occurrence overwrites the earlier ones. This is not guaranteed across all parsers, which is exactly why duplicate keys are dangerous.
How do I detect duplicate keys if parsers stay silent?
Use a dedicated JSON linter or schema validator that flags duplicates, since JSON.parse will not. If you need several values for one concept, store them in an array under a single key instead.

Check Your JSON Now

Our JSON validator detects this error automatically and shows the exact line and column.

Open JSON Validator
Recommended

Cloudways · 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

Start free trial

Related JSON Errors

View all JSON errors