/josser

Json Schema Generator Erlang

Primary LanguageErlangBSD 2-Clause "Simplified" LicenseBSD-2-Clause

JoSSER - JSon Schema Generator ERlang

Build Status

JoSSER is a library in Erlang to generate Json Schema out of Json.

Installation

make deps compile test

Examples

  • create simple json schema
1> josser:make_schema([{<<"key">>, <<"value">>}]).
{ok,[{<<"$schema">>,<<"http://json-schema.org/schema#">>},
     {<<"properties">>,
      [{<<"key">>,[{<<"type">>,<<"string">>}]}]}]}
2> josser:make_schema([{<<"key">>, 123}]).
{ok,[{<<"$schema">>,<<"http://json-schema.org/schema#">>},
     {<<"properties">>,
      [{<<"key">>,[{<<"type">>,<<"integer">>}]}]}]}
  • create json schema with values as metadata
1> josser:make_schema([{<<"key">>, <<"{\"type\": \"integer\", \"min\":0}">>}], [{value_as_metadata, true}]).
{ok,[{<<"$schema">>,<<"http://json-schema.org/schema#">>},
     {<<"properties">>,
      [{<<"key">>,[{<<"type">>,<<"integer">>},{<<"min">>,0}]}]}]}
  • create json schema with custom types (object and array not yet supported)
1> josser:make_custom_schema([{<<"key">>, <<"{\"type\": \"custom_type\"}">>}], 
                             {json_term, [{<<"custom_type">>, [{<<"type">>, <<"integer">>}, {<<"maximum">>, 10}]}]}).
{ok,[{<<"$schema">>,<<"http://json-schema.org/schema#">>},
     {<<"properties">>,
      [{<<"key">>,
        [{<<"type">>,<<"integer">>},{<<"maximum">>,10}]}]}]}

make_custom_schema get CustomTypes argument as:

  • {file, "path/to/file.json"}

  • or:

{json_text, <<"{\"custom_type\": {\"type\": \"string\", \"description\": \"description\"}, 

                                  \"other_custom_type\": {...}}">>}
 ```
  • or:

{json_term, [{<<"custom_type">>, [{<<"type">>, <<"string">>}]}]}
 ```

Contributing

If you see something missing or incorrect, do not hesitate to create an issue or pull request. Thank you!