Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=71c7ff547793b732ad58ca96160b00ff
sha512=5d5f7d1751e9e614d8b17017ceb97033642bf8aafeb167ad73123fcd770d400b66657c6938e5b367e070fe4ac239d1038abd49003c5329bb1b274e97320e32bb
Description
Added to opam-repository:
README
ocaml-jsonschema
JSON Schema draft-07 validator for OCaml.
Pure OCaml implementation. Compiles schemas into validator functions for repeated use.
Packages
- jsonschema-core —
$refresolution, JSON Pointer, registry, regex engine, instance model - jsonschema-validation — All 37 draft-07 validation keywords + 17 format validators
Installation
opam pin add jsonschema-core .
opam pin add jsonschema-validation .Usage
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)) errorsValidation keywords
- Type: type, enum, const
- Numeric: multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum
- String: maxLength, minLength, pattern
- Array: items, additionalItems, maxItems, minItems, uniqueItems, contains
- Object: properties, patternProperties, additionalProperties, maxProperties, minProperties, required, dependencies, dependentRequired, propertyNames
- Logic: allOf, anyOf, oneOf, not
- Conditional: if/then/else
- Format: date-time, date, time, email, idn-email, hostname, idn-hostname, uri, uri-reference, iri, iri-reference, uri-template, ipv4, ipv6, json-pointer, relative-json-pointer, regex
- Content: contentEncoding (base64), contentMediaType (application/json)
Format validation
Format 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).
Test suite results
JSON-Schema-Test-Suite draft-07:
- Mandatory: 922/922 (100%)
- Format: 535/535 (100%)
- Optional: 98/118 (83.1%)
- Total: 1555/1575 (98.7%)
Known limitations
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.
License
ISC
Optional Dependencies
None
Used by (1)
Conflicts
None
Build status
Results of building jsonschema-core with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.1.0 (this version) | n/a | n/a | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure