noTopLevelLiterals (JSON)
Language JSON (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.4.7 - Diagnostic Category:
lint/nursery/noTopLevelLiterals - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
json/top-level-interop
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noTopLevelLiterals": "error" } } }}Description
Section titled “Description”Require the JSON top-level value to be an array or object.
Modern JSON allows an object, array, string, number, boolean, or null at the top level.
Older parsers based on RFC 4627 accept only
an object or array. Restricting the top level to those two forms improves compatibility and
leaves room to add more fields or items later.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”"just a string"code-block.json:1:1 lint/nursery/noTopLevelLiterals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Expected the top-level value to be an array or object.
> 1 │ "just a string"
│ ^^^^^^^^^^^^^^^
2 │
ℹ Some JSON parsers only support objects or arrays as the root element. Wrap your value in an array or object to ensure compatibility.
ℹ 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.
42code-block.json:1:1 lint/nursery/noTopLevelLiterals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Expected the top-level value to be an array or object.
> 1 │ 42
│ ^^
2 │
ℹ Some JSON parsers only support objects or arrays as the root element. Wrap your value in an array or object to ensure compatibility.
ℹ 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.
truecode-block.json:1:1 lint/nursery/noTopLevelLiterals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Expected the top-level value to be an array or object.
> 1 │ true
│ ^^^^
2 │
ℹ Some JSON parsers only support objects or arrays as the root element. Wrap your value in an array or object to ensure compatibility.
ℹ 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.
nullcode-block.json:1:1 lint/nursery/noTopLevelLiterals ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Expected the top-level value to be an array or object.
> 1 │ null
│ ^^^^
2 │
ℹ Some JSON parsers only support objects or arrays as the root element. Wrap your value in an array or object to ensure compatibility.
ℹ 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.
{ "property": "value", "otherProperty": 123}["element", "anotherElement"]{}[]Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.