boudra

boudra

Jaxon: A very fast and flexible JSON parser with streaming support

Hello :wave:,

Why another JSON parser? While working on my side project Sqlify.io, which is written in Elixir, I was in need of a JSON parser capable of parsing gigabytes worth of JSON documents without holding them all in memory and crash the VM, at the time I started using JSX but parsing big files was horribly slow, so inspired by Jiffy I started making my own parser, and started working on Jaxon.

Here’s a quick overview on how Jaxon works:

Jaxon’s default parser, which is implemented as a NIF (other implementations can be provided), takes a JSON document binary and returns a list of events like so:

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

Then the decoder takes a list of events and evaluates them to an Elixir term:

iex(1)> Jaxon.Decoder.events_to_term([:start_object, {:string, "key"}, :colon, {:boolean, true}
, :end_object])
{:ok, %{"key" => true}}

There’s much more to it but as you can imagine, doing it this way means that both parsing and decoding can happen in a streaming fashion like so:

"large_file.json"
|> File.stream!()
|> Jaxon.Stream.query(Jaxon.Path.decode!("$.users.id"))
|> Enum.to_list()

Interested? here are some links to check it out:

Github: https://github.com/boudra/jaxon
Hex.pm: https://hex.pm/packages/jaxon

Thanks :hugs:

Most Liked

mbenatti

mbenatti

Good work!

I’m wondering, maybe you can share your experience and contribute on Provide "jason_native" · Issue #9 · michalmuskala/jason · GitHub

Where Next?

Popular in Discussions Top

Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
AstonJ
If a newbie asked you about Phoenix Contexts, how would you explain the basics to them? Feel free to be as concise or in-depth as you li...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14027 124
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
sergio
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages. It also goes on to call Elix...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
restack_oslo
Hello, Please pardon me for any faux paux. I am 46 and this is my first time on a forum of any kind. I wanted to to get answers from tho...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
fireproofsocks
This is more of a general question, but I’m wondering how other people in the community think about the pattern matching in function sign...
New
Qqwy
Looking at the stacks that existing large companies have used, WhatsApp internally uses Mnesia to store the messages, while Discord uses ...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31013 112
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54120 245
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

We're in Beta

About us Mission Statement