Skip to content

noDuplicateObjectKeys

  • Rule available since: v1.0.0
  • Diagnostic Category: lint/suspicious/noDuplicateObjectKeys
  • This rule is recommended, which means is enabled by default.
  • This rule doesn’t have a fix.
  • The default severity of this rule is error.

Disallow two keys with the same name inside objects.

{
"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 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"
}
biome.json
{
"linter": {
"rules": {
"suspicious": {
"noDuplicateObjectKeys": "error"
}
}
}
}