useConsistentObjectKeys (JSON)
Summary
Section titled “Summary”- Rule available since:
v2.5.14 - Diagnostic Category:
lint/nursery/useConsistentObjectKeys - This rule has an unsafe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
json/no-unnormalized-keys
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useConsistentObjectKeys": "error" } } }}Description
Section titled “Description”Enforce JSON keys with consistent Unicode representation.
Unicode characters can have different internal representations that look identical. For example, “é” can be stored as one code point (U+00E9) or as “e” plus a combining accent (U+0065 + U+0301). Unicode normalization converts text to a standard form (such as NFC) so visually identical keys share the same representation. This avoids confusing behavior in JSON objects where equality checks and key lookups should treat matching text consistently.
More on Unicode normalization can be found here.
Options
Section titled “Options”Select the Unicode representation that keys must follow.
Default: NFC
NFC: Canonical Decomposition followed by Canonical Composition
{ "linter": { "rules": { "nursery": { "useConsistentObjectKeys": { "level": "on", "options": { "form": "NFC" } } } } }}{ "caf\u0065\u0301": "espresso"}code-block.json:2:5 lint/nursery/useConsistentObjectKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This object key mixes Unicode characters that can be encoded in more than one way.
1 │ {
> 2 │ "caf\u0065\u0301": "espresso"
│ ^^^^^^^^^^^^^^^^^
3 │ }
4 │
ℹ Characters that look identical can have different byte representations, so such keys may fail to compare as equal.
ℹ Rewrite the key so equivalent characters use a single, consistent Unicode encoding.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Rewrite the key using a consistent Unicode encoding.
1 1 │ {
2 │ - ····"caf\u0065\u0301":·"espresso"
2 │ + ····"café":·"espresso"
3 3 │ }
4 4 │
NFD: Canonical Decomposition
{ "linter": { "rules": { "nursery": { "useConsistentObjectKeys": { "level": "on", "options": { "form": "NFD" } } } } }}{ "\u00C5": "precomposed A-ring"}code-block.json:2:5 lint/nursery/useConsistentObjectKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This object key mixes Unicode characters that can be encoded in more than one way.
1 │ {
> 2 │ "\u00C5": "precomposed A-ring"
│ ^^^^^^^^
3 │ }
4 │
ℹ Characters that look identical can have different byte representations, so such keys may fail to compare as equal.
ℹ Rewrite the key so equivalent characters use a single, consistent Unicode encoding.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Rewrite the key using a consistent Unicode encoding.
1 1 │ {
2 │ - ····"\u00C5":·"precomposed·A-ring"
2 │ + ····"Å":·"precomposed·A-ring"
3 3 │ }
4 4 │
NFKC: Compatibility Decomposition followed by Canonical Composition
{ "linter": { "rules": { "nursery": { "useConsistentObjectKeys": { "level": "on", "options": { "form": "NFKC" } } } } }}{ "\u00BD": "circled digit one"}code-block.json:2:5 lint/nursery/useConsistentObjectKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This object key mixes Unicode characters that can be encoded in more than one way.
1 │ {
> 2 │ "\u00BD": "circled digit one"
│ ^^^^^^^^
3 │ }
4 │
ℹ Characters that look identical can have different byte representations, so such keys may fail to compare as equal.
ℹ Rewrite the key so equivalent characters use a single, consistent Unicode encoding.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Rewrite the key using a consistent Unicode encoding.
1 1 │ {
2 │ - ····"\u00BD":·"circled·digit·one"
2 │ + ····"1⁄2":·"circled·digit·one"
3 3 │ }
4 4 │
NFKD: Compatibility Decomposition
{ "linter": { "rules": { "nursery": { "useConsistentObjectKeys": { "level": "on", "options": { "form": "NFKD" } } } } }}{ "\u00BD": "vulgar fraction one half"}code-block.json:2:5 lint/nursery/useConsistentObjectKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This object key mixes Unicode characters that can be encoded in more than one way.
1 │ {
> 2 │ "\u00BD": "vulgar fraction one half"
│ ^^^^^^^^
3 │ }
4 │
ℹ Characters that look identical can have different byte representations, so such keys may fail to compare as equal.
ℹ Rewrite the key so equivalent characters use a single, consistent Unicode encoding.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Rewrite the key using a consistent Unicode encoding.
1 1 │ {
2 │ - ····"\u00BD":·"vulgar·fraction·one·half"
2 │ + ····"1⁄2":·"vulgar·fraction·one·half"
3 3 │ }
4 4 │
Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.