dorkhub

SchemaStore.nvim

πŸ› JSON schemas for Neovim

b0o
Luaβ˜… 1kβ‘‚ 20 forksApache-2.0updated 4 days ago
visit the demogit clone https://github.com/b0o/SchemaStore.nvim.gitb0o/SchemaStore.nvim

SchemaStore.nvim

License: Apache 2.0 Test Status Build Status Used By LazyVim Used By LunarVim

A Neovim plugin that provides the SchemaStore catalog for use with jsonls and yamlls.

Install

Lazy.nvim:

  "b0o/schemastore.nvim",

Packer:

use "b0o/schemastore.nvim"

Usage

To use SchemaStore.nvim with lspconfig + jsonls:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas(),
      validate = { enable = true },
    },
  },
}

For an explanation of why the validate = { enable = true } option is recommended, see #8.

yamlls is also supported:

require('lspconfig').yamlls.setup {
  settings = {
    yaml = {
      schemaStore = {
        -- You must disable built-in schemaStore support if you want to use
        -- this plugin and its advanced options like `ignore`.
        enable = false,
        -- Avoid TypeError: Cannot read properties of undefined (reading 'length')
        url = "",
      },
      schemas = require('schemastore').yaml.schemas(),
    },
  },
}

To use a subset of the catalog, you can select schemas by name (see the catalog for a full list):

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        select = {
          '.eslintrc',
          'package.json',
        },
      },
      validate = { enable = true },
    },
  },
}

To ignore certain schemas from the catalog:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        ignore = {
          '.eslintrc',
          'package.json',
        },
      },
      validate = { enable = true },
    },
  },
}

Note that the select and ignore options are mutually exclusive and attempting to use them together will throw an error.

When using select with extra, schemas from extra are not automatically includedβ€”you must explicitly list them in the select array.

To replace certain schemas from the catalog with your own:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        replace = {
          ['package.json'] = {
            description = 'package.json overridden',
            fileMatch = { 'package.json' },
            name = 'package.json',
            url = 'https://example.com/package.json',
          },
          -- Or you can override just the url
          ['package.json'] = 'https://example.com/package.json',
        },
      },
      validate = { enable = true },
    },
  },
}

If you want to include additional schemas, you can use extra:

require('lspconfig').jsonls.setup {
  settings = {
    json = {
      schemas = require('schemastore').json.schemas {
        extra = {
          {
            description = 'My custom JSON schema',
            fileMatch = 'foo.json',
            name = 'foo.json',
            url = 'https://example.com/schema/foo.json',
          },
          {
            description = 'My other custom JSON schema',
            fileMatch = { 'bar.json', '.baar.json' },
            name = 'bar.json',
            url = 'https://example.com/schema/bar.json',
          },
        },
      },
      validate = { enable = true },
    },
  },
}

To use a local schema file, specify the path using the file:// scheme or plain file paths:

require("schemastore").json.schemas({
  extra = {
    {
      description = "Local JSON schema",
      fileMatch = "local.json",
      name = "local.json",
      url = "file:///path/to/your/schema.json", -- or '/path/to/your/schema.json'
    },
  },
})

License

Β© 2021-2026 Maddison Cohodas and Contributors.

Released under the Apache 2.0 License.

more like this

YAMLDuino

YAML <=> JSON converter for ESP32, ESP8266, RP2040 and possibly other devices

Cβ˜… 58

vim-jsonpath

Vim plugin that lets you navigate JSON documents using dot.notation.paths

Vim scriptβ˜… 96

search

search projects, people, and tags