noDuplicateObjectKeys (JSON)
Summary
Section titled “Summary”- Rule available since:
v1.0.0 - Diagnostic Category:
lint/suspicious/noDuplicateObjectKeys - This rule is recommended, meaning it is enabled by default.
- This rule doesn’t have a fix.
- The default severity of this rule is error.
- Sources:
- Same as
json/no-duplicate-keys
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noDuplicateObjectKeys": "error" } } }}Description
Section titled “Description”Disallow duplicate keys in JSON objects.
When a key appears more than once, many parsers keep only the last value and silently discard the earlier ones. Unique keys prevent ambiguous or lost data.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”{ "title": "New title", "title": "Second title"}code-block.json:2:3 lint/suspicious/noDuplicateObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The key title was already declared.
1 │ {
> 2 │ "title": "New title",
│ ^^^^^^^
3 │ "title": "Second title"
4 │ }
ℹ This is where a duplicated key was declared again.
1 │ {
2 │ "title": "New title",
> 3 │ "title": "Second title"
│ ^^^^^^^
4 │ }
5 │
ℹ If a key is defined multiple times, only the last definition takes effect. Previous definitions are ignored.
{ "title": "New title", "secondTitle": "Second title"}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.