This document covers all validation rules and configuration options provided by eslint-plugin-json.
Uses ESLint's glob pattern to apply all json/ rules. This is the most commonly used configuration that enables comprehensive JSON validation.
// Configuration using ESLint glob pattern
rules: {
'json/*': 'error' // Apply all json/ rules with error severity
'json/*': 'warn' // Apply all json/ rules with warning severity
'json/*': ['error', 'allowComments'] // Allow comments in JSON
'json/*': ['error', { allowComments: true }] // Allow comments (object syntax)
}Alias for applying all validation rules. Functionally identical to the * rule below.
rules: {
'json/json': 'error', // Apply all rules
'json/json': ['error', { allowComments: true }] // Apply all rules, allow comments
}Individual rule named "*" that applies all validation rules and handles comment validation.
rules: {
'json/*': 'error', // Apply all rules with error severity
'json/*': ['error', { allowComments: true }] // Apply all rules, allow comments
}Options:
'allowComments' (string): Shorthand to allow JSON comments{ allowComments: boolean } (object): Explicit comment controlHandles undefined/unspecified JSON parsing errors.
rules: {
'json/undefined': 'error'
}Detects invalid characters in JSON content.
rules: {
'json/invalid-character': 'error'
}Validates Unicode character usage in JSON.
rules: {
'json/invalid-unicode': 'error'
}Checks for invalid escape sequences in strings.
rules: {
'json/invalid-escape-character': 'error'
}Detects unterminated string literals.
rules: {
'json/unexpected-end-of-string': 'error'
}Detects malformed number literals.
rules: {
'json/unexpected-end-of-number': 'error'
}Validates that object properties are properly defined.
rules: {
'json/property-expected': 'error'
}Ensures commas are present where required between elements.
rules: {
'json/comma-expected': 'error'
}Validates that colons separate keys and values in objects.
rules: {
'json/colon-expected': 'error'
}Ensures values are provided where required.
rules: {
'json/value-expected': 'error'
}Validates array closing brackets and comma placement.
rules: {
'json/comma-or-close-backet-expected': 'error'
}Validates object closing braces and comma placement.
rules: {
'json/comma-or-close-brace-expected': 'error'
}Detects trailing commas in arrays and objects.
rules: {
'json/trailing-comma': 'error'
}Identifies duplicate keys within JSON objects.
rules: {
'json/duplicate-key': 'error'
}Validates JSON comment usage based on configuration.
rules: {
'json/comment-not-permitted': 'error'
'json/comment-not-permitted': ['error', 'allowComments']
'json/comment-not-permitted': ['error', { allowComments: true }]
}Detects unterminated comment blocks.
rules: {
'json/unexpected-end-of-comment': 'error'
}Validates enum value constraints when schema is provided.
rules: {
'json/enum-value-mismatch': 'error'
}Handles schema resolution and validation errors.
rules: {
'json/schema-resolve-error': 'error'
}Catches validation errors not covered by specific rules.
rules: {
'json/unknown': 'error'
}Basic configuration that applies all validation rules with error severity.
const config = {
files: ['**/*.json'],
plugins: { json },
rules: {
'json/*': 'error'
},
processor: 'json/json'
};Configuration that allows JSON comments while applying all other validations.
const config = {
files: ['**/*.json'],
plugins: { json },
rules: {
'json/*': ['error', { allowComments: true }]
},
processor: 'json/json'
};Basic configuration for legacy ESLint format.
const config = {
plugins: ['json'],
rules: {
'json/*': 'error'
}
};Legacy configuration allowing comments.
const config = {
plugins: ['json'],
rules: {
'json/*': ['error', { allowComments: true }]
}
};All rules accept the same optional configuration schema:
const ruleSchema = [
{
anyOf: [
{
enum: ['allowComments']
},
{
type: 'object',
properties: {
allowComments: { type: 'boolean' }
},
additionalProperties: false
}
]
}
];// Fine-grained control over specific validations
export default [
{
files: ["**/*.json"],
plugins: { json },
rules: {
'json/trailing-comma': 'error',
'json/duplicate-key': 'error',
'json/comment-not-permitted': 'warn'
},
processor: 'json/json'
}
];// Different rules for different file patterns
export default [
{
files: ["**/config/*.json"],
plugins: { json },
rules: {
'json/*': ['error', { allowComments: true }] // Allow comments in config files
},
processor: 'json/json'
},
{
files: ["**/data/*.json"],
plugins: { json },
rules: {
'json/*': 'error' // Strict validation for data files
},
processor: 'json/json'
}
];{
"extends": ["plugin:json/recommended-legacy"],
"overrides": [
{
"files": ["**/config/*.json"],
"rules": {
"json/*": ["error", {"allowComments": true}]
}
}
]
}