
A Haskell implementation of the most commonly used JSON Schema specification (Draft 4).
Notes
-
As of 2017 json-schema-org has begun releasing new drafts of the standard. Once this work stabilizes
hjsonschemawill add coverage for the latest draft. -
Requires pcre (
pkgs.pcrein Nixpkgs). -
Schemas with circular references can cause infinite loops. hjsonschema does loop detection but it may not be solid yet -- please open an issue if you find a situation where it fails.
Example
See here.
Tests
Run all tests:
stack test
Run only local tests:
stack test hjsonschema:local
Run remote tests (makes GETs to json-schema.org, also temporarily starts an HTTP server on port 1234):
stack test hjsonschema:remote
Details
Goals
-
Be a correct and fast implementation of the spec.
-
Be a useful reference for implementers in other languages. Haskell's high level nature, expressive type system and referential transparency suit this purpose well.
Good Parts
-
Passes all the required tests in the language agnostic test suite. NOTE: due to an issue with the test suite this isn't true at the moment, see #175.
-
Very modular, which should make it easy to support future versions of the specification.
Bad Parts
-
Uses the pcre-heavy regular expression library for the "pattern" validator. It should use a library based on the ECMA 262 regex dialect, which the spec requires.
-
Currently doesn't support the optional
"format"validators.
Vendoring
-
JSON-Schema-Test-Suiteis vendored from commit # c1b12bf699f29a04b4286711c6e3bbfba66f21e5 here. -
src/draft4.jsonis from commit # c1b12bf699f29a04b4286711c6e3bbfba66f21e5 here. The root ref in remote ref test has been modified to fix #175.
Credits
TJ Weigel created the logo.
Tim Baumann wrote aeson-schema, on which hjsonschema's test code and its implementation of SchemaGraph were based.
Julian Berman maintains the fantastic language agnostic test suite.