Skip to content

noTopLevelLiterals (JSON)

Language JSON (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noTopLevelLiterals": "error"
}
}
}
}

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.

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

42
code-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.

true
code-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.

null
code-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"]
{}
[]