Skip to content

json-schema-validator/no-invalid

validate object with JSON Schema.

  • ⚙️ This rule is included in "plugin:json-schema-validator/recommended".

📖 Rule Details

This rule validates the file with JSON Schema and reports errors.

Now loading...

🔧 Options

json5
{
    "json-schema-validator/no-invalid": [
        "error",
        {
            "schemas": [
                {
                    "fileMatch": [".eslintrc.json"],
                    "schema": {/* JSON Schema Definition */} // or string
                }
            ],
            "useSchemastoreCatalog": true,
            "mergeSchemas": true // or ["$schema", "options", "catalog"]
        }
    ]
}
  • schemas ... Define an array of any JSON Schema.
    • fileMatch ... A list of known file names (or globs) that match the schema.
    • schema ... An object that defines a JSON schema. Or the path of the JSON schema file or URL.
  • useSchemastoreCatalog ... If true, it will automatically configure some schemas defined in https://www.schemastore.org/api/json/catalog.json. Default true
  • mergeSchemas ... If true, it will merge all schemas defined in schemas, at the $schema field within files, and the catalogue. If an array is given, it will merge only schemas from the given sources. Default false

This option can also be given a JSON schema file or URL. This is useful for configuring with the /* eslint */ directive comments.

Now loading...

Use with .vue

This rule supports .vue custom blocks.

Example:

vue
<i18n>
{
    "en": {
        "hello": "Hello"
    }
}
</i18n>

You must also install eslint-plugin-vue to enable .vue files validation. See here for details.

To match a custom block, use a glob like this:

json5
{
    // If you want to match the <i18n> block.
    "fileMatch": ["**/*blockType=i18n*"],
    "schema": { "type": "object" /* JSON Schema Definition */ }
}

The following custom blocks will try to test if it matches with the virtual filenames.

vue
<i18n lang="yaml">
# path/to/foo.vue/i18n.yaml?vue&type=custom&blockType=i18n&lang=yaml
foo: bar
</i18n>

<i18n lang="json">
// path/to/foo.vue/i18n.json?vue&type=custom&blockType=i18n&lang=json
{ "foo": "bar" }
</i18n>

<i18n>
// path/to/foo.vue/i18n.json?vue&type=custom&blockType=i18n
{ "foo": "bar"}
</i18n>

📚 Further reading

🚀 Version

This rule was introduced in eslint-plugin-json-schema-validator v0.1.0

🔍 Implementation