Skip to content

Commit

Permalink
Merge pull request #18 from boudra/feat/value-streamer
Browse files Browse the repository at this point in the history
Jaxon v2
  • Loading branch information
boudra committed May 7, 2020
2 parents fb638f7 + fb96b42 commit 7a3360c
Show file tree
Hide file tree
Showing 91 changed files with 209,960 additions and 822 deletions.
38 changes: 26 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
language: elixir
elixir:
- 1.6.5
otp_release:
- 19.3
- 20.3
before_script:
- MIX_ENV=test mix compile --warnings-as-errors
cache:
directories:
- ~/.hex
- ~/.mix
- _build
matrix:
include:
- otp_release: 21.3
elixir: 1.9
- otp_release: 21.3
elixir: 1.8
- otp_release: 21.3
elixir: 1.7
install:
- mix local.rebar --force
- mix local.hex --force
- mix deps.get
env:
- MIX_ENV=test
script:
- mix compile --warnings-as-errors
- mix format --check-formatted --dry-run
- MIX_ENV=test mix coveralls.travis
- mix coveralls.travis
# - mix dialyzer --halt-exit-status
after_script:
- MIX_ENV=docs mix deps.get
- MIX_ENV=docs mix inch.report
sudo: required
dist: trusty
- mix inch.report
before_cache:
- mix deps.clean --all --build
- mix clean --build
cache:
directories:
- _build
Expand Down
146 changes: 0 additions & 146 deletions BENCHMARKS.md

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ all: priv/decoder.so

priv/decoder.so: c_src/decoder_nif.c c_src/decoder.c
mkdir -p priv
$(CC) $(CFLAGS) -std=c99 -O3 -I$(ERL_INCLUDE_PATH) c_src/decoder*.c -o priv/decoder.so
$(CC) $(CFLAGS) -msse2 -mavx2 -std=c99 -O3 -I$(ERL_INCLUDE_PATH) c_src/decoder*.c -o priv/decoder.so

clean:
@rm -rf priv/decoder.so
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ Links:

---

[Click here if you want to use the 1.x version](https://github.com/boudra/jaxon/tree/fb638f76945236822e8e015ee4b4d79b8255b71e)

## Installation

```elixir
def deps do
[
{:jaxon, "~> 1.0"}
{:jaxon, "~> 2.0"}
]
end
```
Expand All @@ -44,15 +46,15 @@ Query a binary JSON stream:

```elixir
iex> stream = [~s({"jaxon":"rocks","array":[1,2]})]
iex> stream |> Jaxon.Stream.query([:root, "array", :all]) |> Enum.to_list()
iex> stream |> Jaxon.Stream.from_enumerable() |> Jaxon.Stream.query([:root, "array", :all]) |> Enum.to_list()
[1, 2]
```

Query a binary JSON stream using JSON path expressions:

```elixir
iex> stream = [~s({"jaxon":"rocks","array":[1,2]})]
iex> stream |> Jaxon.Stream.query(Jaxon.Path.decode!("$.array[*]")) |> Enum.to_list()
iex> stream |> Jaxon.Stream.from_enumerable() |> Jaxon.Stream.query(Jaxon.Path.parse!("$.array[*]")) |> Enum.to_list()
[1, 2]
```

Expand All @@ -61,6 +63,7 @@ Query a large file without holding the whole file in memory:
```elixir
"large_file.json"
|> File.stream!()
|> Jaxon.Stream.from_enumerable()
|> Jaxon.Stream.query([:root, "users", :all, "id"])
|> Enum.to_list()
```
Expand All @@ -70,8 +73,8 @@ Query a large file without holding the whole file in memory:
Jaxon first parses the JSON string into a list of events/tokens:

```elixir
iex(1)> Jaxon.Parsers.NifParser.parse(~s({"key":true}))
[:start_object, {:string, "key"}, :colon, {:boolean, true}, :end_object]
iex(1)> Jaxon.Parsers.NifParser.parse(~s({"key":true}), [])
{:ok, [:start_object, {:string, "key"}, :colon, {:boolean, true}, :end_object]}
```

These are all the available events:
Expand Down Expand Up @@ -108,7 +111,7 @@ config :jaxon, :parser, Jaxon.Parsers.NifParser # only NifParser is supported at
Then, the decoder's job is to take a list of events and aggregate it into a Elixir term:

```elixir
iex(4)> Jaxon.Decoder.events_to_term([:start_object, {:string, "key"}, :colon, {:boolean, true}
iex(4)> Jaxon.Decoders.Value.decode([:start_object, {:string, "key"}, :colon, {:boolean, true}
, :end_object])
{:ok, %{"key" => true}}
```
Expand All @@ -127,7 +130,7 @@ To run the benchmarks, execute:
mix bench.decode
```

See the benchmarks here: [benchmarks](/BENCHMARKS.md)
See the decode benchmarks here: [benchmarks](https://boudra.github.io/jaxon/benchmark_results/decode.html)

## License

Expand Down
Loading

0 comments on commit 7a3360c

Please sign in to comment.