json/no-empty-keys
Disallow empty keys in JSON objects
JSON allows "" as a key, but it's almost always a mistake: a name that was never filled in, or a template that printed nothing. Many tools that read the file into an object or a database column can't use such a key.
A key that contains only whitespace also counts as empty.
Configure#
Off by default. It needs an ESLint config that says which files are in the language:
eslint.config.js
import json from "@eslint/json";
export default [
{
files: ["**/*.json"],
plugins: { json },
language: "json/json",
rules: { "json/no-empty-keys": "error" },
},
];It also works with json/jsonc and json/json5.
Examples#
example.json1 problem
{
""Empty key found.: "app"
}example.json1 problem
{
" "Empty key found.: "app"
}example.jsonNo problems
{
"name": "app",
"description": ""
}