# Thoas

A blazing fast JSON parser and generator in pure Erlang.

Thoas is an Erlang conversion of the Elixir based [Jason library][jason]. 

The parser and generator are at least twice as fast as other Elixir/Erlang
libraries. The performance is comparable to `jiffy`, which is implemented in C
as a NIF. Thoas and Jason are usually only twice as slow.

Both parser and generator fully conform to
[RFC 8259]( and
[ECMA 404](
standards. The parser is tested using [JSONTestSuite](

If you like this library thank Michał and the Jason contributors. They did all
the hard work!

## Installation

### Erlang

% rebar.config
{deps, [thoas]}

### Gleam

gleam add thoas

### Elixir

# mix.exs
def deps do
  [{:thoas, "~> 0.1"}]

## Basic Usage

> thoas:encode(#{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"}).
<<"{\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}">>

> thoas:decode(<<"{\"age"\:44,"\name"\:\"Steve Irwin\",\"nationality\":\"Australian\"}">>).
{ok, #{<<"age">> => 44, <<"name">> => <<"Steve Irwin">>, <<"nationality">> => <<"Australian">>}}

## Benchmarks

Benchmarks against most popular Elixir & Erlang json libraries can be executed after
going into the `bench/` folder and then executing `mix bench.encode` and `mix bench.decode`.
A HTML report of the benchmarks (after their execution) can be found in
`bench/output/encode.html` and `bench/output/decode.html` respectively.

## Differences to Jason

Thoas has a couple feature differences compared to Jason.

- Thoas is written in Erlang.
- Thoas has no support for Elixir protocols.
- Thoas has no support for pretty-printing JSON.
- Thoas has no support for detecting duplicate object keys.
- Thoas always uses binary strings when decoding object keys.
- Thoas has an additional non-recursive encoder API that may be useful when
  working within statically typed languages such as Gleam.

## Why not use Jason?

Jason rocks, but if you're writing Erlang, Gleam, or some other BEAM language
you probably don't want to pull in the Elixir compiler and their standard
libraries just to get a really fast JSON parser. Thoas is just Erlang and uses
rebar3, so it can be easily added as a dependency to projects written in any
BEAM language.

Thoas also has a non-recursive API that may be useful from statically typed
languages or in highly performance constrained scenarios.

## License

Thoas is released under the Apache License 2.0 - see the [LICENSE](LICENSE) file.

Thoas is based off of [Jason][jason], which is also Apache 2.0 licenced.

Some elements of tests and benchmarks have their origins in the
[Poison library]( and were initially licensed under [CC0-1.0](