Exonerate

A JSONSchema -> Elixir compiler

example workflow

Documentation

Documentation is available at: https://hexdocs.pm/exonerate

Performance

Accuracy benchmark relative to GPT-3.5 and GPT-4

Performance (speed) benchmark relative to other elixir JSONSchema libraries

JsonSchema support scope:

Currently supports JSONSchema drafts 4, 6, 7, 2019, 2020. except:

Note:

Installation

Add the following lines to your mix.exs

  defp deps do
    [
      {:exonerate, "~> 1.1.0", runtime: false},
    ]
  end

Quick Start

defmodule SchemaModule do
  require Exonerate

  Exonerate.function_from_string(:def, :validate_input, """
  {
    "type":"object",
    "properties":{
      "parameter":{"type":"integer"}
    }
  }
  """)
end
iex> SchemaModule.validate_input("some string")
{:error, error_value: "some string", instance_location: "/", absolute_keyword_location: "#/type"}

iex> SchemaModule.validate_input(%{"parameter" => "2"})
{:error, error_value: "2", instance_location: "/parameter", absolute_keyword_location: "#/properties/parameter/type"}

iex> SchemaModule.validate_input(%{"parameter" => 2})
:ok

Licensing notes

This software contains verbatim code from https://github.com/json-schema-org/JSON-Schema-Test-Suite which is copyright Julian Berman, et. al, and released under the MIT license.