Page
Library
Module
Module type
Parameter
Class
Class type
Source
JSON Schema draft-07 validator for OCaml.
Pure OCaml implementation. Compiles schemas into validator functions for repeated use.
$ref resolution, JSON Pointer, registry, regex engine, instance modelopam pin add jsonschema-core .
opam pin add jsonschema-validation .let schema = Yojson.Safe.from_string {|{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
},
"required": ["name"]
}|}
let validate = Jsonschema_validation.compile schema
let () =
let data = Yojson.Safe.from_string {|{"name": "Alice", "age": 30}|} in
match validate data with
| [] -> print_endline "valid"
| errors -> List.iter (fun e -> print_endline (Jsonschema_core.Error.to_string e)) errorsFormat validators cover RFC 3339 (date/time with leap second UTC conversion), RFC 3986/3987 (URI/IRI with percent-encoding and port validation), RFC 5890/5891/5892/5893 (IDNA2008 hostnames via ocaml-idna), and RFC 5321 (email).
JSON-Schema-Test-Suite draft-07:
20 optional test failures related to ECMA-262 regex Unicode semantics. The re library (ocaml/ocaml-re) operates at byte level without Unicode codepoint support. Affected patterns: \D, \W, \S on multi-byte characters, \uXXXX escapes, UTF-16 surrogate pairs, and Unicode character classes in pattern/patternProperties. Tracking: ocaml-re#24, ocaml-re#592.
ISC