Ir al contenido

noTopLevelLiterals

Esta página aún no está disponible en tu idioma.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noTopLevelLiterals": "error"
}
}
}
}

Require the JSON top-level value to be an array or object.

The JSON specification technically allows any JSON value (object, array, string, number, boolean, or null) to be used as the top-level element of a JSON document. However, some older JSON parsers, especially those created before RFC 7158/4627 was fully adopted, only support objects or arrays as the root element.

Additionally, some security practices (such as those preventing JSON hijacking attacks) rely on the assumption that the top-level value is an object or array. Using an object or array at the top level also provides better extensibility for your data structures over time.

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