Skip to content

Linting json

jq

  • see jq.md
  • Cannot lint hujson or jsonc

check-jsonschema

Buildin schemas

  • Builtin schemas
  • see also src/check_jsonschema/builtin_schemas
  • The '--builtin-schema' flag supports the following schema names:
    • vendor.azure-pipelines
    • vendor.bamboo-spec
    • vendor.bitbucket-pipelines
    • vendor.buildkite
    • vendor.circle-ci
    • vendor.cloudbuild
    • vendor.dependabot
    • vendor.drone-ci
    • vendor.github-actions
    • vendor.github-workflows
    • vendor.gitlab-ci
    • vendor.readthedocs
    • vendor.renovate
    • vendor.taskfile
    • vendor.travis
    • vendor.woodpecker-ci
    • custom.github-workflows-require-timeout

Here the most interesting:

  • gitlab-ci - Validate GitLab CI config against the schema provided by SchemaStore
  • github-actions
  • github-workflows
  • readthedocs
  • renovate

Install

sudo pacman -S check-jsonschema

cli usage

Docs: CLI usage

Builtin schema:

check-jsonschema --builtin-schema vendor.gitlab-ci .gitlab-ci.yml

Schema URL:

check-jsonschema -v \
  --schemafile https://raw.githubusercontent.com/goss-org/goss/master/docs/schema.yaml \
  goss.yaml

pre-commit usage

Usage in pre-commit:

.pre-commit-hooks.yaml

repos:
  - repo: https://github.com/python-jsonschema/check-jsonschema
    rev: 0.23.2
    hooks:
      - id: check-gitlab-ci

Other linters

  • json5format
    • JSON5 formatter that preserves contextual comments
    • Removes quotes from keys which breaks hujson
  • hujsonfmt
    • Formatter for hujson
    • Uses tabs instead of spaces, not configurable
    • Use json5 filetype in Neovim for syntax highlighting
  • json-repair
    • A python module to repair invalid JSON from LLMs

Language servers

  • hrsh7th/jsonls
    • No configuration possible, complains about trailing commas in i.e. hujson
    • Integrated in nvim-lspconfig
    • Last release 2024-05

Outdated