parthenon
is an OTP application that parses AWS Athena structures into Erlang terms.
Inside rebar.config
:
%% ...
{deps, [
%% ...
parthenon
]}.
Inside .app.src
:
%% ...
{applications, [
%% ...
parthenon
]},
%% ...
Inside the code:
ok = parthenon:add_schema(athena_structure, <<"struct<a: int, b: int>">>).
{ok, #{a := 123, b := 456}} = parthenon:decode(athena_structure, <<"{a=123, b=456}">>, [
{object_format, maps}, {key_format, existing_atom}
]).
To test it out from the shell, it is possible to simply do:
application:ensure_all_started(parthenon).
ok = parthenon:add_schema(athena_structure, <<"struct<a: int, b: int>">>).
{ok, #{a := 123, b := 456} = Response} = parthenon:decode(athena_structure, <<"{a=123, b=456}">>, [
{object_format, maps}, {key_format, existing_atom}
]).
ok = parthenon:add_schema(nested_structures, <<"struct<a: int, b: array<struct<c: int, d: string>>>">>).
{ok, #{a := 123, b := [#{c := 456, d := <<"Some test, some test">>}]} = Response2} = parthenon:decode(
nested_structures, <<"{a=123, b=[{c=456, d=Some test, some test}]}">>, [
{object_format, maps}, {key_format, existing_atom}
]
).
%% If `jiffy' is present
<<"{\"b\":456,\"a\":123}">> = jiffy:encode(Response).
<<"{\"b\":[{\"d\":\"Some test, some test\",\"c\":456}],\"a\":123}">> = jiffy:encode(Response2).
You can run all the tests and linters with the rebar3
alias:
rebar3 check