Liking cljdoc? Tell your friends :D

jinx

jinx is a recursive acronym: jinx is not xml-schema

jinx is json-schema!

Clojars CircleCI

Introduction

Almost all Clojure implementations of json schema validators wrap Java libraries. This is generally a good idea.

However, there are some reasons why a native Clojure implementation can be useful:

  • Java libraries compile jsonschema to object graphs, making them inaccessible to many of the data functions in the Clojure core library.

  • On the front-end, it can be painful to have to convert Clojure data to JavaScript objects simply for the purposes of calling a jsonschema validation such as Ajv.

  • Extensibility: JSON Schema is designed to be extended with additional vocabularies. Clojure has some nice open-for-extension mechanisms.

  • Size: Implementing JSON Schema is not that scary in a language as nice as Clojure. There’s not so much code to read, understand and possibly extend.

Scope

This library implements JSON Schema 'draft7' (draft-handrews-json-schema-validation-01).

Status

This is a new project, of alpha status. There may be future incompatible changes ahead.

Most core features are working but there is more work yet to do:

  • Annotation gathering

  • Improved Error messages

  • The schema-path and data-path values on failures

  • Relative json-pointer

This library is tested with the official JSON-Schema-Test-Suite.

Currently, 631 of the 633 official optional and non-optional tests pass. Failing tests include support for uri-template and idn-email.

Schemas

A schema is a Clojure map (or boolean) that should be augmented with metadata by calling juxt.jinx.schema/schema on the schema data:

(juxt.jinx.schema/schema {"type" "object"})

Resolvers

Validation can take an optional options map.

The :resolvers entry should be a collection of resolvers.

  • :juxt.jinx.resolve/built-in is the built-in resolver which will resolve schemas contained in the library, such as the draft7 meta-schema.

  • :juxt.jinx.resolve/default-resolver is a resolver which takes an argument of a map of URIs (or regexes) to values.

    A value can be a schema (which should be pre-processed with schema metadata by calling juxt.jinx.schema/schema).

    A value may also be a function (called with the URI or, in the case of a regex, the result of the regex match):

    {#"http://example.com/schemas/(.*)" (fn [match] {:type "object"
                                                     :path (second match)})}

Developing

When you clone this repository, use the --recursive option to ensure that the official json schema repo is also cloned (as a submodule).

git clone --recursive https://github.com/juxt/jinx

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close