Skip to content

noTopLevelLiterals (JSON)

Language JSON (and super languages)
biome.json
{
"linter": {
"rules": {
"style": {
"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/style/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.

42
code-block.json:1:1 lint/style/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.

true
code-block.json:1:1 lint/style/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.

null
code-block.json:1:1 lint/style/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.

{
"property": "value",
"otherProperty": 123
}
["element", "anotherElement"]
{}
[]