Euneus

An incredibly flexible and performant JSON parser and generator.

Euneus is a rewrite of Thoas.

Like Thoas, both the parser and generator fully conform to RFC 8259 and ECMA 404.

Table of Contents

Installation

Erlang

% rebar.config
{deps, [{euneus, "1.0.2"}]}

Elixir

# mix.exs
def deps do
  [{:euneus, "~> 1.0"}]
end

Basic Usage

1> {ok, JSON} = euneus:encode_to_binary(#{name => #{english => <<"Charmander">>, japanese => <<"ヒトカゲ"/utf8>>}, type => [fire], profile => #{height => 0.6, weight => 8}, ability => #{0 => <<"Blaze">>, 1 => undefined}}).
{ok, <<"{\"name\":{\"english\":\"Charmander\",\"japanese\":\"ヒトカゲ\"},\"profile\":{\"height\":0.6,\"weight\":8},\"type\":[\"fire\"],\"ability\":{\"0\":\"Blaze\",\"1\":null}}">>}

2> euneus:decode(JSON).
{ok,#{<<"ability">> =>
          #{<<"0">> => <<"Blaze">>,<<"1">> => undefined},
      <<"name">> =>
          #{<<"english">> => <<"Charmander">>,
            <<"japanese">> =>
                <<227,131,146,227,131,136,227,130,171,227,130,178>>},
      <<"profile">> => #{<<"height">> => 0.6,<<"weight">> => 8},
      <<"type">> => [<<"fire">>]}}

3> euneus:decode(JSON, #{
    keys => fun
        (<<Char>> = Key, _Opts) when Char >= $0, Char =< $9 ->
            binary_to_integer(Key);
        (Key, _Opts) ->
            binary_to_existing_atom(Key)
    end
}).
{ok,#{name =>
          #{english => <<"Charmander">>,
            japanese =>
                <<227,131,146,227,131,136,227,130,171,227,130,178>>},
      profile => #{height => 0.6,weight => 8},
      type => [<<"fire">>],
      ability => #{0 => <<"Blaze">>,1 => undefined}}}

Data Mapping

[!TIP]

More types can be handled by using custom plugins. Please see the Plugins section for more info.

Erlang ->Encode Options ->JSON ->Decode Options ->Erlang
undefined #{} null #{} undefined
undefined #{} null #{null_term => nil} nil
true #{} true #{} true
false #{} false #{} false
abc #{} "abc" #{} <<"abc">>
"abc" #{} [97,98,99] #{} "abc"
<<"abc">> #{} "abc" #{} <<"abc">>
123 #{} 123 #{} 123
123.45600 #{} 123.456 #{} 123.456
[<<"foo">>,true,0,undefined] #{} ["foo",true,0,null] #{} [<<"foo">>,true,0,undefined]
#{foo => bar} #{} {"foo":"bar"} #{} #{<<"foo">> => <<"bar">>}
#{foo => bar} #{} {"foo":"bar"} #{keys => to_existing_atom} #{foo => <<"bar">>}
#{0 => 0} #{} {"0":0} #{keys => to_integer} #{0 => 0}
{{1970,1,1},{0,0,0}} #{plugins => [datetime]} "1970-01-01T00:00:00Z" #{plugins => [datetime]} {{1970,1,1},{0,0,0}}
{127,0,0,1} #{plugins => [inet]} "127.0.0.1" #{plugins => [inet]} {127,0,0,1}
{16#3ffe,16#b80,16#1f8d,16#2,16#204,16#acff,16#fe17,16#bf38} #{plugins => [inet]} "3ffe:b80:1f8d:2:204:acff:fe17:bf38" #{plugins => [inet]} {16#3ffe,16#b80,16#1f8d,16#2,16#204,16#acff,16#fe17,16#bf38}
<0.92.0> #{plugins => [pid]} "<0.92.0>" #{plugins => [pid]} <0.92.0>
#Port<0.1> #{plugins => [port]} "#Port<0.1>" #{plugins => [port]} #Port<0.1>
[{foo, bar}] #{plugins => [proplist]} {\"foo\":\"bar\"} #{plugins => [proplist]} #{<<"foo">> => <<"bar">>}
#Ref<0.957048870.857473026.108035> #{plugins => [reference]} "#Ref<0.957048870.857473026.108035>" #{plugins => [reference]} #Ref<0.957048870.857473026.108035>
{0,0,0} #{plugins => [timestamp]} "1970-01-01T00:00:00.000Z" #{plugins => [timestamp]} {0,0,0}
{myrecord, val} #{unhandled_encoder => fun({myrecord, Val}, Opts) -> <br> euneus_encoder:encode_list([myrecord, #{key => Val}], Opts)<br><br>end}) ["myrecord", {"key":"val"}] #{arrays => fun([<<"myrecord">>, #{<<"key">> := Val}], _Opts) -><br> {myrecord, binary_to_atom(Val)}<br>end} {myrecord, val}

Why not more built-in types?

The goal of Euneus is to have built-in types that can be commonly encoded and decoded, but the range of types can be easily extended by using plugins. Please see the Plugins section for more info.

Note about proplists

Proplists are not handled by Euneus by default.

There are three options:

  1. Use the built-in, or create your own, proplist plugin;
  2. Convert proplists to maps before the encoding;
  3. Override the list_encoder option in the encoder to handle them, for example:
1> Options = #{
       list_encoder => fun
           ([{K, _} | _] = Proplist, Opts)
             when is_binary(K); is_atom(K); is_integer(K) ->
               Map = proplists:to_map(Proplist),
               euneus_encoder:encode_map(Map, Opts);
           (List, Opts) ->
               euneus_encoder:encode_list(List, Opts)
       end
   }.

2> Proplist = [{foo, bar}, {bar, [{0, ok}]}].

3> euneus:encode_to_binary(Proplist, Options).
{ok,<<"{\"foo\":\"bar\",\"bar\":{\"0\":\"ok\"}}">>}

The reason for that is because it's impossible to know when a list is a proplist and also because a proplist cannot be decoded. Please see the Why not more built-in types? section for more info about this decision.

Plugins

Euneus has a mechanism to easily plug in encoders and decoders. You can use the built-in plugins to handle common types or create your own in a module by implementing the euneus_plugin behavior.

If you have a built-in plugin suggestion, feel free to open a new issue to discuss it.

[!IMPORTANT] The plugins mechanism deprecated the datetime_encoder and the timestamp_encoder option in favor of the datetime and timestamp plugins.

Usage

Encode

euneus:encode(Term, #{plugins => [
    % list of built-in or custom plugins
]})

Decode

euneus:decode(Term, #{plugins => [
    % list of built-in or custom plugins
]})

Built-in Plugins

datetime

Encodes calendar:datetime() to ISO8601 as JSON string and decodes it back, for example:

1> {ok, JSON} = euneus:encode_to_binary({{1970,1,1},{0,0,0}}, #{plugins => [datetime]}).
{ok,<<"\"1970-01-01T00:00:00Z\"">>}

2> euneus:decode(JSON, #{plugins => [datetime]}).
{ok,{{1970,1,1},{0,0,0}}}

inet

Encodes inet:ip_address() to IPV4 or IPV6 as JSON string and decodes it back, for example:

1> {ok, JSON} = euneus:encode_to_binary({127,0,0,1}, #{plugins => [inet]}).
{ok,<<"\"127.0.0.1\"">>}

2> euneus:decode(JSON, #{plugins => [inet]}).
{ok,{127,0,0,1}}

pid

Encodes erlang:pid() to JSON string and decodes it back, for example:

1> {ok, JSON} = euneus:encode_to_binary(list_to_pid("<0.92.0>"), #{plugins => [pid]}).
{ok,<<"\"<0.92.0>\"">>}

2> euneus:decode(JSON, #{plugins => [pid]}).
{ok,<0.92.0>}

port

Encodes erlang:port() to JSON string and decodes it back, for example:

1> {ok, JSON} = euneus:encode_to_binary(list_to_port("#Port<0.1>"), #{plugins => [port]}).
{ok,<<"\"#Port<0.1>\"">>}

2> euneus:decode(JSON, #{plugins => [port]}).
{ok,#Port<0.1>}

proplist

Encodes [{binary() | atom() | integer(), term()}] to JSON object, for example:

1> {ok, JSON} = euneus:encode_to_binary([{foo, bar}], #{plugins => [proplist]}).
{ok,<<"{\"foo\":\"bar\"}">>}

reference

Encodes erlang:reference() to JSON string and decodes it back, for example:

1> {ok, JSON} = euneus:encode_to_binary(make_ref(), #{plugins => [reference]}).
{ok,<<"\"#Ref<0.957048870.857473026.108035>\"">>}

2> euneus:decode(JSON, #{plugins => [reference]}).
{ok,#Ref<0.957048870.857473026.108035>}

timestamp

Encodes erlang:timestamp() to ISO8601 as JSON string and decodes it back, for example:

1> {ok, JSON} = euneus:encode_to_binary({0,0,0}, #{plugins => [timestamp]}).
{ok,<<"\"1970-01-01T00:00:00.000Z\"">>}

2> euneus:decode(JSON, #{plugins => [timestamp]}).
{ok,{0,0,0}}

Differences to Thoas

The main difference between Euneus to Thoas is that Euneus gives more control to encoding or decoding data. All encode functions can be overridden and extended and all decoded data can be overridden and transformed. Also, there is no plugin mechanism in Thoas.

Encode

Available encode options:

#{
    %% nulls defines what terms will be replaced with the null literal (default: [&#39;undefined&#39;]).
    nulls => nonempty_list(),
    %% binary_encoder allow override the binary() encoding.
    binary_encoder => function((binary(), euneus_encoder:options()) -> iolist()),
    %% atom_encoder allow override the atom() encoding.
    atom_encoder => function((atom(), euneus_encoder:options()) -> iolist()),
    %% integer_encoder allow override the integer() encoding.
    integer_encoder => function((integer(), euneus_encoder:options()) -> iolist()),
    %% float_encoder allow override the float() encoding.
    float_encoder => function((float(), euneus_encoder:options()) -> iolist()),
    %% list_encoder allow override the list() encoding.
    list_encoder => function((list(), euneus_encoder:options()) -> iolist()),
    %% map_encoder allow override the map() encoding.
    map_encoder => function((map(), euneus_encoder:options()) -> iolist()),
    %% unhandled_encoder allow encode any custom term (default: raise unsupported_type error).
    unhandled_encoder => function((term(), euneus_encoder:options()) -> iolist()),
    %% escaper allow override the binary escaping (default: json).
    escaper => json
             | html
             | javascript
             | unicode
             | function((binary(), euneus_encoder:options()) -> iolist()),
    error_handler => function(( error | exit | throw
                              , term()
                              , erlang:stacktrace() ) -> euneus_encoder:result()),
    %% plugins extends the encode types.
    plugins => datetime
             | inet
             | pid
             | port
             | proplist
             | reference
             | timestamp
             | module() % that implements the `euneus_plugin` behavior.
}

For example:

1> EncodeOpts = #{
       binary_encoder => fun
           (<<"foo">>, Opts) ->
               euneus_encoder:encode_binary(<<"bar">>, Opts);
           (Bin, Opts) ->
               euneus_encoder:encode_binary(Bin, Opts)
       end,
       unhandled_encoder => fun
           ({_, _, _, _} = Ip, Opts) ->
               case inet:ntoa(Ip) of
                   {error, einval} ->
                       throw(invalid_ip);
                   IpStr ->
                       IpBin = list_to_binary(IpStr),
                       euneus_encoder:encode_binary(IpBin, Opts)
               end;
           (Term, Opts) ->
               euneus_encoder:throw_unsupported_type_error(Term, Opts)
       end,
       error_handler => fun
           (throw, invalid_ip, _Stacktrace) ->
               {error, invalid_ip};
           (Class, Reason, Stacktrace) ->
               euneus_encoder:handle_error(Class, Reason, Stacktrace)
       end
   }.

2> Data = #{<<"foo">> => bar, ipv4 => {127,0,0,1}, none => undefined}.

3> euneus:encode_to_binary(Data, EncodeOpts).
{ok, <<"{\"bar\":\"bar\",\"ipv4\":\"127.0.0.1\",\"none\":null}">>}

4> euneus:encode_to_binary({1270,0,0,1}, EncodeOpts).
{error, invalid_ip}

Decode

Available decode options:

#{
    %% null_term is the null literal override (default: &#39;undefined&#39;).
    null_term => term(),
    %% arrays allow override any array/list().
    arrays => function((list(), euneus_decoder:options()) -> term()),
    %% objects allow override any object/map().
    objects => function((map(), euneus_decoder:options()) -> term()),
    %% keys allow override the keys from JSON objects.
    keys => copy
          | to_atom
          | to_existing_atom
          | to_integer
          | function((binary(), euneus_decoder:options()) -> term()),
    %% values allow override any other term, like array item or object value.
    values => copy
            | to_atom
            | to_existing_atom
            | to_integer
            | function((binary(), euneus_decoder:options()) -> term()),
    %% plugins extends the decode types.
    plugins => datetime
             | inet
             | pid
             | port
             | reference
             | timestamp
             | module() % that implements the `euneus_plugin` behavior.
}

For example:

1> DecodeOpts = #{
      null_term => nil,
      keys => fun
          (<<"bar">>, _Opts) ->
              foo;
          (Key, _Opts) ->
              binary_to_atom(Key)
      end,
      values => fun
          (<<"127.0.0.1">>, _Opts) ->
              {127, 0, 0, 1};
          (Value, _Opts) ->
              Value
      end
   }.

2> JSON = <<"{\"bar\":\"bar\",\"ipv4\":\"127.0.0.1\",\"none\":null}">>.

3> euneus:decode(JSON, DecodeOpts).
{ok,#{foo => <<"bar">>,
      ipv4 => {127,0,0,1},
      none => nil}}

Resuming

Euneus permits resuming the decoding when an invalid token is found. Any value can replace the invalid token by overriding the error_handler option, e.g.:

1> ErrorHandler = fun
      (throw, {{token, Token}, Rest, Opts, Input, Pos, Buffer}, _Stacktrace) ->
          Replacement = foo,
          euneus_decoder:resume(Token, Replacement, Rest, Opts, Input, Pos, Buffer);
      (Class, Reason, Stacktrace) ->
          euneus_decoder:handle_error(Class, Reason, Stacktrace)
   end.

2> Opts = #{error_handler => ErrorHandler}.

3> euneus:decode(<<"[1e999,1e999,{\"foo\": 1e999}]">>, Opts).
{ok,[foo,foo,#{<<"foo">> => foo}]}

[!NOTE]

By using euneus_decoder:resume/6 the replacement will be the null_term option.

Why Euneus over Thoas?

Thoas is incredible, works performant and perfectly fine, but Euneus is more flexible, permitting more customizations, and is more performant than Thoas. See the benchmarks.

The motivation for Euneus is this PR.

Benchmarks

All the latest runs details can be found under the runs directory in the benchmark project.

Encode

Smart encoding

This benchmark uses the JSON smart module via the euneus:encode/1 function. Smart modules only receive the input as the argument, so no option is available to set. Smart modules are the fastest euneus modules.

Blockchain
NameIPSSlower
jiffy11.14 K 
Jason4.60 K2.42x
euneus4.49 K2.48x
thoas3.78 K2.94x
jsone2.54 K4.39x
jsx1.00 K11.18x
Giphy
NameIPSSlower
jiffy1162.06 
Jason429.192.71x
euneus427.232.72x
thoas403.552.88x
jsone213.425.44x
jsx78.7314.76x
GitHub
NameIPSSlower
jiffy3.55 K 
Jason1.51 K2.35x
euneus1.45 K2.44x
thoas1.30 K2.72x
jsone0.67 K5.34x
jsx0.197 K18.01x
GovTrack
NameIPSSlower
jiffy52.04 
Jason17.912.91x
thoas16.563.14x
euneus14.723.53x
jsone8.586.06x
jsx3.0716.95x
Issue 90
NameIPSSlower
jiffy36.73 
Jason27.441.34x
euneus23.241.58x
thoas17.012.16x
jsone16.652.21x
jsx8.754.2x
JSON Generator
NameIPSSlower
jiffy1191.94 
euneus417.782.85x
Jason411.692.9x
thoas405.742.94x
jsone273.004.37x
jsx97.4712.23x
Pokedex
NameIPSSlower
jiffy1669.42 
euneus644.192.59x
Jason628.422.66x
thoas613.912.72x
jsone322.225.18x
jsx108.1015.44x
UTF-8 unescaped
NameIPSSlower
jiffy14.32 K 
Jason10.11 K1.42x
euneus9.40 K1.52x
thoas9.07 K1.58x
jsx4.76 K3.01x
jsone1.83 K7.83x

All benchmark details are available here.

Encoding with empty map as option

This benchmark passes the input and options parsed as the euneus:encode_parsed/2 function arguments. There is no option set, just an empty map, so all the default options are used. This function it's a bit slower than the smart one, but all options are analyzed in the run.

Blockchain
NameIPSSlower
jiffy11.13 K 
Jason4.62 K2.41x
euneus3.92 K2.84x
thoas3.74 K2.98x
jsone2.55 K4.37x
jsx1.01 K11.03x
Giphy
NameIPSSlower
jiffy1163.05 
Jason416.912.79x
thoas396.882.93x
euneus335.543.47x
jsone212.685.47x
jsx79.3014.67x
GitHub
NameIPSSlower
jiffy3.50 K 
Jason1.50 K2.34x
thoas1.28 K2.74x
euneus1.25 K2.81x
jsone0.66 K5.31x
jsx0.199 K17.63x
GovTrack
NameIPSSlower
jiffy51.97 
Jason17.962.89x
euneus17.402.99x
thoas16.463.16x
jsone8.546.09x
jsx3.0816.9x
Issue 90
NameIPSSlower
jiffy36.68 
Jason27.351.34x
euneus24.041.53x
thoas16.942.17x
jsone16.682.2x
jsx8.764.19x
JSON Generator
NameIPSSlower
jiffy1177.53 
euneus409.802.87x
Jason406.642.9x
thoas399.932.94x
jsone270.724.35x
jsx97.8912.03x
Pokedex
NameIPSSlower
jiffy1659.13 
Jason620.012.68x
thoas609.242.72x
euneus487.643.4x
jsone321.065.17x
jsx108.3515.31x
UTF-8 unescaped
NameIPSSlower
jiffy14.36 K 
Jason10.07 K1.43x
euneus9.27 K1.55x
thoas9.07 K1.58x
jsx4.78 K3.0x
jsone1.83 K7.86x

All benchmark details are available here.

Encoding with all built-in plugins

This benchmark passes all the encode built-in plugins to the plugins option:

euneus:parse_encode_opts(#{
  plugins => [
    datetime,
    inet,
    pid,
    port,
    proplist,
    reference,
    timestamp
  ]
}).

It's the slowest euneus encode run, but at the same time it is very efficient.

Blockchain
NameIPSSlower
jiffy11.28 K 
Jason4.59 K2.46x
euneus3.79 K2.97x
thoas3.79 K2.98x
jsone2.54 K4.44x
jsx1.01 K11.2x
Giphy
NameIPSSlower
jiffy1172.88 
Jason424.492.76x
thoas402.262.92x
euneus332.493.53x
jsone213.215.5x
jsx79.3014.79x
GitHub
NameIPSSlower
jiffy3.26 K 
Jason1.52 K2.14x
thoas1.30 K2.51x
euneus1.22 K2.67x
jsone0.66 K4.93x
jsx0.196 K16.62x
GovTrack
NameIPSSlower
jiffy52.16 
Jason18.212.86x
thoas16.953.08x
euneus16.663.13x
jsone8.556.1x
jsx3.1016.83x
Issue 90
NameIPSSlower
jiffy36.70 
Jason27.431.34x
euneus24.121.52x
thoas16.982.16x
jsone16.662.2x
jsx8.784.18x
JSON Generator
NameIPSSlower
jiffy1188.50 
Jason412.202.88x
thoas405.502.93x
euneus397.612.99x
jsone272.444.36x
jsx94.4412.59x
Pokedex
NameIPSSlower
jiffy1648.51 
Jason628.072.62x
thoas613.822.69x
euneus470.183.51x
jsone321.845.12x
jsx108.4515.2x
UTF-8 unescaped
NameIPSSlower
jiffy14.38 K 
Jason10.09 K1.42x
euneus9.41 K1.53x
thoas9.13 K1.57x
jsx4.76 K3.02x
jsone1.79 K8.02x

All benchmark details are available here.

Decode

Smart decoding

This benchmark uses the decode smart module via the euneus:decode/1 function. Smart modules only receive the input as the argument, so no option is available to set. Smart modules are the fastest euneus modules.

Blockchain
NameIPSSlower
jiffy5.94 K 
euneus5.77 K1.03x
Jason5.53 K1.08x
thoas4.87 K1.22x
jsone4.26 K1.39x
jsx1.83 K3.25x
Giphy
NameIPSSlower
jiffy925.19 
thoas498.151.86x
euneus494.101.87x
Jason451.812.05x
jsone278.023.33x
jsx162.975.68x
GitHub
NameIPSSlower
jiffy2.69 K 
euneus2.09 K1.29x
Jason2.01 K1.34x
thoas1.81 K1.49x
jsone1.42 K1.9x
jsx0.51 K5.24x
GovTrack
NameIPSSlower
jiffy27.04 
Jason17.021.59x
euneus16.791.61x
thoas15.691.72x
jsone9.352.89x
jsx4.406.14x
Issue 90
NameIPSSlower
jiffy49.92 
euneus26.621.88x
Jason25.251.98x
jsone23.252.15x
thoas17.792.81x
jsx9.925.03x
JSON Generator (Pretty)
NameIPSSlower
jiffy1143.30 
euneus707.451.62x
Jason696.881.64x
thoas624.071.83x
jsone435.822.62x
jsx185.816.15x
JSON Generator
NameIPSSlower
jiffy698.94 
euneus616.181.13x
Jason591.721.18x
thoas539.941.29x
jsone400.041.75x
jsx176.013.97x
Pokedex
NameIPSSlower
jiffy1.36 K 
euneus1.17 K1.16x
thoas1.15 K1.18x
Jason1.04 K1.3x
jsone0.59 K2.31x
jsx0.26 K5.31x
UTF-8 escaped
NameIPSSlower
jiffy10.41 K 
thoas1.70 K6.14x
Jason1.69 K6.18x
euneus1.47 K7.09x
jsone1.29 K8.09x
jsx1.16 K8.97x
UTF-8 unescaped
NameIPSSlower
jiffy18.12 K 
euneus10.44 K1.74x
Jason10.19 K1.78x
thoas9.60 K1.89x
jsone9.44 K1.92x
jsx6.57 K2.76x

All benchmark details are available here.

Decoding with empty map as option

This benchmark passes the input and options parsed as the euneus:decode_parsed/2 function arguments. There is no option set, just an empty map, so all the default options are used. This function it's a bit slower than the smart one, but all options are analyzed in the run.

Blockchain
NameIPSSlower
jiffy5.98 K 
Jason5.55 K1.08x
thoas4.87 K1.23x
jsone4.28 K1.4x
euneus3.59 K1.67x
jsx1.83 K3.26x
Giphy
NameIPSSlower
jiffy990.34 
thoas497.981.99x
Jason456.782.17x
euneus278.423.56x
jsone277.713.57x
jsx167.265.92x
GitHub
NameIPSSlower
jiffy2.70 K 
Jason2.01 K1.35x
thoas1.82 K1.49x
jsone1.42 K1.91x
euneus1.17 K2.3x
jsx0.52 K5.2x
GovTrack
NameIPSSlower
jiffy27.25 
Jason17.271.58x
thoas15.781.73x
jsone9.552.85x
euneus7.823.49x
jsx4.456.13x
Issue 90
NameIPSSlower
jiffy49.74 
Jason25.261.97x
euneus25.231.97x
jsone23.292.14x
thoas17.982.77x
jsx9.974.99x
JSON Generator (Pretty)
NameIPSSlower
jiffy1162.25 
Jason694.531.67x
thoas625.051.86x
jsone436.442.66x
euneus347.693.34x
jsx191.096.08x
JSON Generator
NameIPSSlower
jiffy696.27 
Jason586.851.19x
thoas541.031.29x
jsone400.671.74x
euneus317.162.2x
jsx181.313.84x
Pokedex
NameIPSSlower
jiffy1.35 K 
thoas1.15 K1.18x
Jason1.04 K1.3x
jsone0.59 K2.29x
euneus0.40 K3.34x
jsx0.26 K5.27x
UTF-8 escaped
NameIPSSlower
jiffy10.38 K 
Jason1.70 K6.09x
thoas1.70 K6.11x
euneus1.45 K7.18x
jsone1.30 K7.97x
jsx1.18 K8.83x
UTF-8 unescaped
NameIPSSlower
jiffy18.07 K 
euneus10.37 K1.74x
Jason10.20 K1.77x
thoas9.59 K1.89x
jsone9.51 K1.9x
jsx6.58 K2.75x

All benchmark details are available here.

Decoding with all built-in plugins

This benchmark passes all the decode built-in plugins to the plugins option:

euneus:parse_decode_opts(#{
  plugins => [
    datetime,
    timestamp,
    pid,
    port,
    reference,
    inet
  ]
}).

[!NOTE]

The proplist plugin is only available for encoding.

It's the slowest euneus decode run, but at the same time it is very efficient.

Blockchain
NameIPSSlower
jiffy5.98 K 
Jason5.55 K1.08x
thoas4.87 K1.23x
jsone4.28 K1.4x
euneus3.59 K1.67x
jsx1.83 K3.26x
Giphy
NameIPSSlower
jiffy990.34 
thoas497.981.99x
Jason456.782.17x
euneus278.423.56x
jsone277.713.57x
jsx167.265.92x
GitHub
NameIPSSlower
jiffy2.70 K 
Jason2.01 K1.35x
thoas1.82 K1.49x
jsone1.42 K1.91x
euneus1.17 K2.3x
jsx0.52 K5.2x
GovTrack
NameIPSSlower
jiffy27.25 
Jason17.271.58x
thoas15.781.73x
jsone9.552.85x
euneus7.823.49x
jsx4.456.13x
Issue 90
NameIPSSlower
jiffy49.74 
Jason25.261.97x
euneus25.231.97x
jsone23.292.14x
thoas17.982.77x
jsx9.974.99x
JSON Generator (Pretty)
NameIPSSlower
jiffy1162.25 
Jason694.531.67x
thoas625.051.86x
jsone436.442.66x
euneus347.693.34x
jsx191.096.08x
JSON Generator
NameIPSSlower
jiffy696.27 
Jason586.851.19x
thoas541.031.29x
jsone400.671.74x
euneus317.162.2x
jsx181.313.84x
Pokedex
NameIPSSlower
jiffy1.35 K 
thoas1.15 K1.18x
Jason1.04 K1.3x
jsone0.59 K2.29x
euneus0.40 K3.34x
jsx0.26 K5.27x
UTF-8 escaped
NameIPSSlower
jiffy10.38 K 
Jason1.70 K6.09x
thoas1.70 K6.11x
euneus1.45 K7.18x
jsone1.30 K7.97x
jsx1.18 K8.83x
UTF-8 unescaped
NameIPSSlower
jiffy18.07 K 
euneus10.37 K1.74x
Jason10.20 K1.77x
thoas9.59 K1.89x
jsone9.51 K1.9x
jsx6.58 K2.75x

All benchmark details are available here.

Tests

There are Eunit tests in euneus_encoder and euneus_decoder and tests suites in a specific project under the euneus_test directory. Euneus has more than 330 tests.

Also, the parser is tested using JSONTestSuite and all tests passes:

JSON Test Suite

See the Euneus parser in JSONTestSuite.

[!NOTE]

All of the JSONTestSuite tests are embedded in Euneus tests.

Smart modules

Euneus has modules that permit customizations and others that use the default options. The modules without customizations are called smart. The smart versions are faster because they do not do any option checks.

If you are good to go with the default options, please use the smart versions:

Credits

Euneus is a rewrite of Thoas, so all credits go to Michał Muskała, Louis Pilfold, also both Jason and Thoas contributors. Thanks for the hard work!

Why the name Euneus?

Euneus is the twin brother of Thoas.

Sponsors

If you like this tool, please consider sponsoring me. I'm thankful for your never-ending support :heart:

I also accept coffees :coffee:

"Buy Me A Coffee"

Contributing

Issues

Feel free to submit an issue on Github.

Installation

# Clone this repo
git clone git@github.com:williamthome/euneus.git

# Navigate to the project root
cd euneus

# Compile (ensure you have rebar3 installed)
rebar3 compile

Commands

# Benchmark euneus:encode/1
$ make bench.encode
# Benchmark euneus:decode/1
$ make bench.decode
# Run all tests
$ make test
# Run all tests and dialyzer
$ make check

[!NOTE]

Open the Makefile to see all commands.

License

Euneus is released under the Apache License 2.0.

Euneus is based on Thoas, which is also Apache 2.0 licensed.

Some elements have their origins in the Poison library and were initially licensed under CC0-1.0.