or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdjson-processing.mdrules-and-configuration.md
tile.json

rules-and-configuration.mddocs/

Rules and Configuration

This document covers all validation rules and configuration options provided by eslint-plugin-json.

Global Rules

json/* (ESLint Pattern)

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)
}

json/json

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
}

json/*

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 control

Individual Validation Rules

Syntax Error Rules

json/undefined

Handles undefined/unspecified JSON parsing errors.

rules: {
  'json/undefined': 'error'
}

json/invalid-character

Detects invalid characters in JSON content.

rules: {
  'json/invalid-character': 'error'
}

json/invalid-unicode

Validates Unicode character usage in JSON.

rules: {
  'json/invalid-unicode': 'error'
}

json/invalid-escape-character

Checks for invalid escape sequences in strings.

rules: {
  'json/invalid-escape-character': 'error'
}

String and Number Parsing Rules

json/unexpected-end-of-string

Detects unterminated string literals.

rules: {
  'json/unexpected-end-of-string': 'error'
}

json/unexpected-end-of-number

Detects malformed number literals.

rules: {
  'json/unexpected-end-of-number': 'error'
}

Structural Rules

json/property-expected

Validates that object properties are properly defined.

rules: {
  'json/property-expected': 'error'
}

json/comma-expected

Ensures commas are present where required between elements.

rules: {
  'json/comma-expected': 'error'
}

json/colon-expected

Validates that colons separate keys and values in objects.

rules: {
  'json/colon-expected': 'error'
}

json/value-expected

Ensures values are provided where required.

rules: {
  'json/value-expected': 'error'
}

json/comma-or-close-backet-expected

Validates array closing brackets and comma placement.

rules: {
  'json/comma-or-close-backet-expected': 'error'
}

json/comma-or-close-brace-expected

Validates object closing braces and comma placement.

rules: {
  'json/comma-or-close-brace-expected': 'error'
}

json/trailing-comma

Detects trailing commas in arrays and objects.

rules: {
  'json/trailing-comma': 'error'
}

json/duplicate-key

Identifies duplicate keys within JSON objects.

rules: {
  'json/duplicate-key': 'error'
}

Comment Rules

json/comment-not-permitted

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 }]
}

json/unexpected-end-of-comment

Detects unterminated comment blocks.

rules: {
  'json/unexpected-end-of-comment': 'error'
}

Schema and Validation Rules

json/enum-value-mismatch

Validates enum value constraints when schema is provided.

rules: {
  'json/enum-value-mismatch': 'error'
}

json/schema-resolve-error

Handles schema resolution and validation errors.

rules: {
  'json/schema-resolve-error': 'error'
}

Special Rules

json/unknown

Catches validation errors not covered by specific rules.

rules: {
  'json/unknown': 'error'
}

Predefined Configurations

Flat Config Format (ESLint v9+)

recommended

Basic configuration that applies all validation rules with error severity.

const config = {
  files: ['**/*.json'],
  plugins: { json },
  rules: {
    'json/*': 'error'
  },
  processor: 'json/json'
};

recommended-with-comments

Configuration that allows JSON comments while applying all other validations.

const config = {
  files: ['**/*.json'],
  plugins: { json },
  rules: {
    'json/*': ['error', { allowComments: true }]
  },
  processor: 'json/json'
};

Legacy Config Format

recommended-legacy

Basic configuration for legacy ESLint format.

const config = {
  plugins: ['json'],
  rules: {
    'json/*': 'error'
  }
};

recommended-with-comments-legacy

Legacy configuration allowing comments.

const config = {
  plugins: ['json'],
  rules: {
    'json/*': ['error', { allowComments: true }]
  }
};

Rule Configuration Schema

All rules accept the same optional configuration schema:

const ruleSchema = [
  {
    anyOf: [
      {
        enum: ['allowComments']
      },
      {
        type: 'object',
        properties: {
          allowComments: { type: 'boolean' }
        },
        additionalProperties: false
      }
    ]
  }
];

Usage Examples

Custom Configuration

// 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'
  }
];

Mixed Configurations

// 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'
  }
];

Legacy Override Example

{
  "extends": ["plugin:json/recommended-legacy"],
  "overrides": [
    {
      "files": ["**/config/*.json"],
      "rules": {
        "json/*": ["error", {"allowComments": true}]
      }
    }
  ]
}