noEmptyObjectKeys (JSON)
Language JSON (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.4.7 - Diagnostic Category:
lint/suspicious/noEmptyObjectKeys - This rule isn’t recommended, so you need to enable it.
- This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
json/no-empty-keys
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noEmptyObjectKeys": "error" } } }}Description
Section titled “Description”Disallow empty keys in JSON objects.
JSON allows empty strings as object keys, but they are difficult to identify in logs, error messages, and source code. This rule reports keys that are empty or contain only whitespace, because they are usually accidental. Use a short, meaningful name instead.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”{ "": "value"}code-block.json:2:3 lint/suspicious/noEmptyObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty object key.
1 │ {
> 2 │ "": "value"
│ ^^
3 │ }
4 │
ℹ Empty keys often cause confusion and may cause issues with parsers or processors. Either remove this property or provide a meaningful key name.
{ "validKey": "value", "": "another value"}code-block.json:3:3 lint/suspicious/noEmptyObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty object key.
1 │ {
2 │ "validKey": "value",
> 3 │ "": "another value"
│ ^^
4 │ }
5 │
ℹ Empty keys often cause confusion and may cause issues with parsers or processors. Either remove this property or provide a meaningful key name.
{ " ": "space as key"}code-block.json:2:3 lint/suspicious/noEmptyObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty object key.
1 │ {
> 2 │ " ": "space as key"
│ ^^^
3 │ }
4 │
ℹ Empty keys often cause confusion and may cause issues with parsers or processors. Either remove this property or provide a meaningful key name.
{ "\t": "tab as key"}code-block.json:2:3 lint/suspicious/noEmptyObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty object key.
1 │ {
> 2 │ "\t": "tab as key"
│ ^^^^
3 │ }
4 │
ℹ Empty keys often cause confusion and may cause issues with parsers or processors. Either remove this property or provide a meaningful key name.
{ "\n": "newline as key"}code-block.json:2:3 lint/suspicious/noEmptyObjectKeys ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unexpected empty object key.
1 │ {
> 2 │ "\n": "newline as key"
│ ^^^^
3 │ }
4 │
ℹ Empty keys often cause confusion and may cause issues with parsers or processors. Either remove this property or provide a meaningful key name.
{ "key": "value"}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.