gojsonschema

A Go implementation of JSON Schema, supporting draft-04, draft-06, and draft-07 validation.

Library
Go
vv1.2.0
2,740 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
48 /100 Fair
Development Activity 0
Maintenance 20
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 76
Code Quality 78
Innovation 58
Learning Curve 70

gojsonschema is a pure-Go library that implements the JSON Schema specification for validating JSON documents against a schema. It supports draft-04, draft-06, and draft-07, with automatic draft detection via the $schema keyword or a hybrid mode that merges functionality across drafts when no version is declared.

The library exposes several loader types — reference (file or HTTP URL), raw JSON string, and native Go struct/map — so schemas and documents can come from disk, the network, or in-memory data without extra marshaling steps. Validation results carry structured, typed errors (RequiredError, InvalidTypeError, StringLengthGTEError, and dozens more) with contextual field paths, making it straightforward to build user-facing error messages or feed results into other tooling.

Because it has no runtime dependencies beyond two sibling xeipuuv packages (gojsonpointer and gojsonreference) and testify for tests, it drops cleanly into API servers, config validators, and CLI tools that need to enforce a JSON contract without pulling in a heavier framework.

What You Get

  • Support for JSON Schema draft-04, draft-06, and draft-07, with autodetection based on the $schema keyword
  • Multiple loader types — file/HTTP references, raw JSON strings, and native Go structs or maps — for both schemas and documents
  • A SchemaLoader for registering and resolving multiple interlinked schemas via $id and $ref before compiling
  • Optional meta-schema validation so malformed schemas are caught at AddSchema/Compile time instead of failing silently later
  • Built-in format checkers for email, hostname, ipv4/ipv6, uri, uuid, date-time, json-pointer, and more
  • A customizable locale and template-function system for translating or reformatting validation error messages

Common Use Cases

  • Validating incoming JSON request bodies in an HTTP API against a published schema before processing them
  • Enforcing the shape of configuration files (YAML/JSON) at application startup, failing fast with field-level errors
  • Checking that generated or third-party JSON payloads conform to a contract before they are persisted or forwarded
  • Building developer tooling (linters, schema validators, CI checks) that need standards-compliant JSON Schema support in Go

Under The Hood

Architecture

The library separates schema compilation from document validation across a small set of collaborating files: schemaLoader.go and schemaPool.go resolve and cache schema documents (including remote $ref fetches) into a schemaPool, schema.go recursively parses a loaded document into a tree of subSchema nodes attached to a Schema struct, and validation.go walks that tree against an input document via validateRecursive, accumulating typed errors into a Result. A schemaReferencePool prevents redundant re-resolution of repeated $ref targets. This produces a clear two-phase pipeline — compile once via NewSchema/SchemaLoader.Compile, then validate many documents cheaply against the same compiled *Schema — and the loader abstraction (JSONLoader interface) is the seam that would need to change if a new input source (e.g. streaming) were added.

Tech Stack

Written in plain Go with no external runtime dependencies apart from two sibling libraries from the same author, gojsonpointer and gojsonreference, used respectively for JSON Pointer resolution and URI/reference handling; github.com/stretchr/testify is a test-only dependency. The module targets Go via go.mod with no build tooling beyond go build/go test, and CI (via .travis.yml) exercises Go 1.11 through 1.13, though the library itself uses no version-specific language features and continues to build on modern Go toolchains.

Code Quality

The repository has substantial test coverage: schema_test.go, jsonschema_test.go, schemaLoader_test.go, format_checkers_test.go, and utils_test.go, backed by a testdata/ directory organized per draft (draft4, draft6, draft7) plus extra and remotes fixtures, indicating the official JSON Schema test suite is exercised directly. Errors are modeled as a family of typed structs (RequiredError, InvalidTypeError, NumberGTEError, etc.) implementing a common ResultError interface rather than being returned as opaque strings, which gives callers structured access to Type(), Field(), Value(), and Details(). Naming and file organization are consistent and domain-driven (one concern per file: errors.go, format_checkers.go, locales.go, result.go), though the project predates Go modules-era conventions like generics or contextual error wrapping.

What Makes It Unique

Unlike many ad-hoc JSON validators, gojsonschema treats draft compliance as a first-class concern: it can autodetect a document’s declared draft version, validate schemas themselves against their meta-schema before use, and mix draft-04/06/07 schemas together via $ref as long as each declares $schema. Its locale system, including custom text/template error-message functions, is more extensive than typical validation libraries, letting consumers localize or reformat error output without forking the library.

Used by 8 apps in this directory

Go
86%
Apache 2.0

Argo Workflows

Data Engineering · Devops

17,050

The most popular Kubernetes-native workflow engine for orchestrating containerized DAGs, ML pipelines, CI/CD, and parallel batch jobs at scale.

View details
96
Repo Health
90
Technical
68
Dependency
Built with
Go 86%
TypeScript 10%
Updated 1 weeks ago
Go
59%
Apache 2.0

Cog

AI Development · Developer Tools · Devops

9,490

An open-source CLI that packages machine learning models into standard, production-ready Docker containers — no Dockerfile wrangling, no CUDA version hell.

View details
85
Repo Health
88
Technical
68
Dependency
Built with
Go 59%
Rust 17%
HTML 13%
Updated 1 weeks ago
Go
71%
Other

Convoy

Developer Tools · Devops

2,883

Convoy is an open-source, cloud-native webhooks gateway that ingests events over HTTP or straight from Kafka, SQS, Google Pub/Sub, and RabbitMQ, then reliably delivers them to subscriber endpoints with signed payloads, automatic retries, circuit breaking, and JavaScript-based transformations.

View details
88
Repo Health
81
Technical
66
Dependency
Built with
Go 71%
TypeScript 15%
HTML 12%
Updated 1 weeks ago
Go
76%
Other

Flipt

Developer Tools · Devops

4,926

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
90
Repo Health
83
Technical
68
Dependency
Built with
Go 76%
TypeScript 23%
Updated 6 days ago
Go
97%
MIT

Formance Ledger

Databases · Developer Tools · Invoicing Finance

1,448

The programmable open source core ledger for fintech — build money-moving applications with atomic multi-posting transactions, account-based modeling, and Numscript, a built-in DSL for financial logic.

View details
91
Repo Health
8
Technical
68
Dependency
Built with
Go 97%
Updated 6 days ago
Go
71%
Apache 2.0

OSV.dev

Security

3,001

Google's open-source vulnerability database that maps CVEs to exact package versions across 50+ ecosystems with a public API and data dumps.

View details
87
Repo Health
82
Technical
66
Dependency
Built with
Go 71%
Python 19%
Updated 1 weeks ago
Go
93%
MIT

Plandex

AI Code Assistants

15,777

An open-source, terminal-based AI coding agent built for large tasks and real codebases — with its own version control for plans, a 2M-token effective context window, and self-hosted or cloud deployment.

View details
50
Repo Health
70
Technical
67
Dependency
Built with
Go 93%
Updated 1 years ago
Go
98%
Other

Tyk API Gateway

Developer Tools · Devops

10,869

Cloud-native, high-performance open-source API gateway for REST, GraphQL, gRPC, and TCP — built in Go since 2014 with no feature lockout.

View details
97
Repo Health
78
Technical
67
Dependency
Built with
Go 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers