Skip to content

bel-framework/bel-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bel-framework/bel-json

A JSON encoder and decoder built on top of the json module proposed in EEP 68 and introduced in OTP 27. Uses json_polyfill to support OTP versions < 27.

Encode

1> bel_json:encode(#{foo => bar}).
<<"{\"foo\":\"bar\"}">>

Null

1> bel_json:encode([foo, null, undefined, bar], #{null_values => [null, undefined]}).
<<"[\"foo\",null,null,\"bar\"]">>

Proplist

1> bel_json:encode([{foo, foo}, bar], #{list_codecs => [proplist]}).
<<"{\"foo\":\"foo\",\"bar\":true}">>

Datetime

1> bel_json:encode([{foo, foo}, bar], #{tuple_codecs => [datetime]}).
<<"{\"foo\":\"2024-04-29T22:34:35Z\"}">>

Timestamp

1> bel_json:encode({0,0,0}, #{tuple_codecs => [timestamp]}).
<<"\"1970-01-01T00:00:00.000Z\"">>

IPv4

1> bel_json:encode({0,0,0,0}, #{tuple_codecs => [ipv4]}).
<<"\"0.0.0.0\"">>

IPv6

1> bel_json:encode({16#fe80,0,0,0,16#204,16#acff,16#fe17,16#bf38}, #{tuple_codecs => [ipv6]}).
<<"\"fe80::204:acff:fe17:bf38\"">>

Record

% -record(foo, {foo, bar}).
1> bel_json:encode(#foo{foo = foo, bar = bar}, #{tuple_codecs => [{record, [{foo, record_info(fields, foo)}]}]}).
<<"{\"foo\":\"foo\",\"bar\":\"bar\"}">>

Decode

3> bel_json:decode(<<"{\"foo\":\"bar\"}">>).
#{<<"foo">> => <<"bar">>}

Build

$ rebar3 compile

About

JSON encoder and decoder for OTP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages