Skip to content

sourcemeta/blaze

Repository files navigation

Blaze

The ultra high-performance JSON Schema validator for C++ with support for JSON Schema Draft 4, Draft 6, Draft 7, 2019-09, and 2020-12.

DOI Supported Dialects

Draft 2020-12 Draft 2019-09 Draft 7 Draft 6 Draft 4

Want to use Blaze without writing C++? Check out our JSON Schema CLI, which is powered by Blaze, and offers advanced functionality like validate --trace for debugging schema evaluation.

Benchmark

The 2025 paper Blaze: Compiling JSON Schema for 10x Faster Validation (also published on PVLDB) presents a reproducible benchmark comparing Blaze against a number of popular JSON Schema validators, concluding that Blaze is on average at least 10x faster than competitors given a large set of representative schemas and instances.

Features

  • Performance: Blaze compiles JSON Schema into a lower-level intermediate language for ultra fast evaluation. It can achieve schema validation in the nano-second range, making it a perfect fit for low-latency gateways and validation of large datasets

  • Single-Threaded: Blaze evaluation is single-threaded by design. In servers and gateways, parallelism naturally occurs across requests. Each incoming validation gets its own thread, scaling across all cores with zero coordination overhead. Parallelising a single evaluation across multiple cores may look faster in isolation, but monopolises resources and degrades both throughput and tail latency under concurrent load

  • Compliance: Blaze achieves a 100% compliance score in the official Bowtie benchmark, while popular validators like AJV only achieve an average 85% compliance. It also supports the Standard Output format (Flag, and Basic). Furthermore, Blaze is built and maintained by a JSON Schema TSC member, ensuring compliance even on subtle aspects that the test suite does not cover yet

  • Extensibility: Blaze supports the implementation of custom vocabularies of arbitrary complexity, and the ability to setup custom resolution of external schemas from arbitrary sources, like from HTTP, filesystem, databases, etc

  • Annotations: Blaze is one of the few implementations that fully supports annotation extraction during evaluation to augment instances with semantic information, making it a great fit for data science scenarios. Blaze also adheres to the annotations official test suite

  • No Code Generation: Blaze does not generate C++ code that needs to be built with a compiler toolchain. Instead, it compiles schemas into a set of low-level instructions serializable as JSON. The evaluator is schema-agnostic, executing these instructions without any knowledge of the original schema. This design means that systems can accept and validate against unknown schemas at runtime

  • Numerics: Blaze supports high precision decimals. For performance reasons, these representations are only used if the numbers fail to be parsed at the JSON level using the 64-bit signed and IEEE 764 double precision representations or (as a heuristic) if the numbers explicitly opt-in to exponent scientific notation

  • Format Assertion: Blaze fully implements the Format Assertion vocabulary from Draft 4 to 2020-12 (with partial Draft 3 support), covering every built-in format defined by the relevant specifications, including internationalised hostnames and IRIs

Example

Blaze is designed to be easy to use, while at the same time providing extensive hooks for supporting custom vocabularies, resolving external schemas, and more.

// (1) Get a JSON Schema
const auto schema{sourcemeta::core::parse(R"JSON({
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "string"
})JSON")};

// (2) Compile the JSON Schema into an optimised representation
const auto compiled_schema{sourcemeta::blaze::compile(
  schema,

  // These options allow you tweak how Blaze works,
  // the JSON Schema vocabularies it understands,
  // and how to resolve references to external schemas
  sourcemeta::core::schema_walker,
  sourcemeta::core::schema_resolver,
  sourcemeta::blaze::default_schema_compiler,

  // Fast validation means getting to a boolean result
  // as fast as possible. Check out the documentation
  // for how to get detailed error information and/or
  // collect JSON Schema annotations
  sourcemeta::blaze::Mode::FastValidation)};

// (3) Get a JSON instance
const sourcemeta::core::JSON instance{"Hello Blaze!"};

// (4) Validate the instance against the schema
sourcemeta::blaze::Evaluator evaluator;
const auto result{evaluator.validate(compiled_schema, instance)};
if (result) {
  std::cout << "Success!\n";
}

Ports

Documentation

Refer to the project website for documentation: https://blaze.sourcemeta.com.

Roadmap

  • Support running the validator on simdjson

Contributors

Blaze was designed and developed by a team of passionate JSON Schema developers and researchers.

About

The ultra high-performance C++ JSON Schema validator, providing validation even down to the nano-second range (depends on schemas and hardware) along with perfect compliance scores. Supports Draft 4, Draft 6, Draft 7, 2019-09 and 2020-12. For both servers and embedded devices

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Contributors