Skip to content

noDuplicateJsonKeys (since v1.0.0)

Diagnostic Category: lint/nursery/noDuplicateJsonKeys

Disallow two keys with the same name inside a JSON object.

{
"title": "New title",
"title": "Second title"
}
nursery/noDuplicateJsonKeys.js:2:3 lint/nursery/noDuplicateJsonKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   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"
}