Skip to content

noDuplicateJsonKeys (自 v1.0.0)

诊断类别:lint/nursery/noDuplicateJsonKeys

¥Diagnostic Category: lint/nursery/noDuplicateJsonKeys

禁止在 JSON 对象内使用两个同名的键。

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

¥Examples

¥Invalid

{
"title": "New title",
"title": "Second title"
}
code-block.json: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.
  

¥Valid

{
"title": "New title",
"secondTitle": "Second title"
}

¥Related links