Tool: CLI for JSON Schema Validation with Line Number and detailed error information

Quick post.

My goal was, I thought, simple:

Run a CLI tool which checks if a JSON document is valid for a JSON schema and returns the line numbers with error details

So I head over to json-schema.org/tools and look for one.

I try:

  • ajv-cli ⛔ Doesn’t handle field type of date
  • boon ❌ Doesn’t show line numbers
  • Test-Json ❌ built in powershell cmdlet - Doesn’t handle if-then-else schemas or show line info
  • check-jsonschema ❌ no line info

Along with that most of them didn’t give great error messages.

Frustrated, I remembered using jsonschemavalidator.net and double checked.

It outputs all the info and shows how to do it in code using the Newtonsoft library ✨!

So a few hours later there is now github.com/lawrencegripper/gripdev-json-schema-validator

A CLI and PowerShell Module which gives detailed info and formats it nicely to show to users too. For example:

❌ JSON validation failed!
   Found the following errors:

  ❌ Error Details:
    └─ Message: Required properties are missing from object: city.
    └─ Location: Line 4, Position 14
    └─ Path: address
    └─ Value: city

The CLI and CmdLet also output structured JSON data so you can use it to annotate files on builds or write scripts. For example, the readme shows how to use it to Annotate with GitHub actions.

Enjoy!

Big shout out to James King (Newtonsoft) for the heavy lifting here using the AGPL version of his library.