Skip to content

Instantly share code, notes, and snippets.

@voluntas
Last active December 16, 2015 11:39
Show Gist options
  • Save voluntas/5429166 to your computer and use it in GitHub Desktop.
Save voluntas/5429166 to your computer and use it in GitHub Desktop.
jesse コトハジメ

jesse コトハジメ

更新:2013-04-21
バージョン:0.0.0
作者:@voluntas
URL:http://voluntas.github.io/

jesse

https://github.com/klarna/jesse

JSON Schema: core definitions and terminology
http://tools.ietf.org/html/draft-zyp-json-schema-04

RFC Draft をベースに作られた JSON Schema です。

> application:start(jesse).
ok
> Schema = jsonx:decode(<<"{\"items\": {\"type\": \"integer\"}}">>).
{[{<<"items">>,{[{<<"type">>,<<"integer">>}]}}]}
> jesse:add_schema(some_key, Schema).
ok
> Json1 = jsonx:decode(<<"[1, 2, 3]">>).
[1,2,3]
> jesse:validate(some_key, Json1).
{ok,[1,2,3]}
> Json2 = jsonx:decode(<<"[1, \"x\"]">>).
[1,<<"x">>]
> jesse:validate(some_key, Json2).
{error,{data_invalid,<<"x">>,not_integer,
                     {[{<<"type">>,<<"integer">>}]}}}
> Json3 = jsonx:decode(<<"1">>).
1
> jesse:validate(some_key, Json3).
{ok,1}

items の形式は integer である必要があります。 list だろうが map だろうがなんだろうが integer でなければいけません。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment