Skip to content

Pascal736/json_typedef

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Typedef

Hex.pm Documentation

A pure Elixir implementation of RFC8927. Validates data against JSON Typedef schemas.

Installation

If available in Hex, the package can be installed by adding typedef to your list of dependencies in mix.exs:

def deps do
  [
    {:typedef, "~> 0.0.1"}
  ]
end

Quick Start

iex> schema = %{
...>   "properties" => %{
...>     "name" => %{"type" => "string"},
...>     "age" => %{"type" => "uint32"},
...>     "phones" => %{
...>       "elements" => %{
...>         "type" => "string"
...>       }
...>     }
...>   }
...> }
iex>
iex> {:ok, true} = Typedef.valid_schema?(schema)
iex>
iex> Typedef.validate(schema, %{
...>   "name" => "John Doe",
...>   "age" => 43,
...>   "phones" => ["+44 1234567", "+44 2345678"]
...> })
{:ok, true}
iex>
iex> {:error, errors} = Typedef.validate(schema, %{
...>   "age" => "43",
...>   "phones" => ["+44 1234567", 999]
...> })
iex> errors
[%Typedef.ErrorPath{instance_path: ["age"], schema_path: ["properties", "age", "type"]}, %Typedef.ErrorPath{instance_path: ["name"], schema_path: ["properties", "name"]}, %Typedef.ErrorPath{instance_path: ["phones", 1], schema_path: ["properties", "phones", "elements", "type"]}]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages