All Projects → boudra → Jaxon

boudra / Jaxon

Licence: apache-2.0
Streaming JSON parser for Elixir

Programming Languages

elixir
2628 projects
erlang
1774 projects

Projects that are alternatives of or similar to Jaxon

Lol Html
Low output latency streaming HTML parser/rewriter with CSS selector-based API
Stars: ✭ 566 (+290.34%)
Mutual labels:  stream, parser, streaming
Stream Parser
⚡ PHP7 / Laravel Multi-format Streaming Parser
Stars: ✭ 391 (+169.66%)
Mutual labels:  json, parser, streaming
Java
jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go
Stars: ✭ 1,308 (+802.07%)
Mutual labels:  json, parser
Swurg
Parse OpenAPI documents into Burp Suite for automating OpenAPI-based APIs security assessments (approved by PortSwigger for inclusion in their official BApp Store).
Stars: ✭ 94 (-35.17%)
Mutual labels:  json, parser
Nginx Vod Module
NGINX-based MP4 Repackager
Stars: ✭ 1,378 (+850.34%)
Mutual labels:  stream, streaming
Athenax
SQL-based streaming analytics platform at scale
Stars: ✭ 1,178 (+712.41%)
Mutual labels:  stream, streaming
Internettools
XPath/XQuery 3.1 interpreter for Pascal with compatibility modes for XPath 2.0/XQuery 1.0/3.0, custom and JSONiq extensions, XML/HTML parsers and classes for HTTP/S requests
Stars: ✭ 82 (-43.45%)
Mutual labels:  json, parser
Hls.js
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
Stars: ✭ 10,791 (+7342.07%)
Mutual labels:  stream, streaming
Saw
Fast, multi-purpose tool for AWS CloudWatch Logs
Stars: ✭ 1,071 (+638.62%)
Mutual labels:  json, streaming
Twitchrecover
Twitch VOD tool which recovers all VODs including those that are sub only or deleted.
Stars: ✭ 123 (-15.17%)
Mutual labels:  stream, streaming
Alembic
⚗️ Functional JSON Parser - Linux Ready 🐧
Stars: ✭ 115 (-20.69%)
Mutual labels:  json, parser
Tiny Json
The tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable.
Stars: ✭ 127 (-12.41%)
Mutual labels:  json, parser
Cssparser.js
cssparser.js is a parser that generate json from css with matched orders & structures.
Stars: ✭ 61 (-57.93%)
Mutual labels:  json, parser
Cypher Stream
Neo4j Cypher queries as Node.js object streams
Stars: ✭ 58 (-60%)
Mutual labels:  stream, streaming
Go
A high-performance 100% compatible drop-in replacement of "encoding/json"
Stars: ✭ 10,248 (+6967.59%)
Mutual labels:  json, parser
Barely json
A Python parser for data that only looks like JSON
Stars: ✭ 56 (-61.38%)
Mutual labels:  json, parser
Rtmp Rtsp Stream Client Java
Library to stream in rtmp and rtsp for Android. All code in Java
Stars: ✭ 1,338 (+822.76%)
Mutual labels:  stream, streaming
Json Autotype
Automatic Haskell type inference from JSON input
Stars: ✭ 139 (-4.14%)
Mutual labels:  json, parser
Saber
Window-Based Hybrid CPU/GPU Stream Processing Engine
Stars: ✭ 35 (-75.86%)
Mutual labels:  stream, streaming
Fast Xml Parser
Validate XML, Parse XML to JS/JSON and vise versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback
Stars: ✭ 1,021 (+604.14%)
Mutual labels:  json, parser

Jaxon ⚡️ Hex.pm Build Status Inline docs Coverage Status

Jaxon is a fast JSON parser that can stream any JSON document without holding it all in memory.

Jaxon fully conforms to the RFC 8259 and ECMA 404 standards and is tested against JSONTestSuite.

Roadmap:

  • Make an alternative parser in Elixir, for those who don't want to use NIFs.
  • JSON events to string Encoder.

Links:


Click here if you want to use the 1.x version

Installation

def deps do
  [
    {:jaxon, "~> 2.0"}
  ]
end

Simple decoding

Decode a binary:

iex> Jaxon.decode(~s({"jaxon":"rocks","array":[1,2]}))
{:ok, %{"array" => [1, 2], "jaxon" => "rocks"}}

iex> Jaxon.decode!(~s({"jaxon":"rocks","array":[1,2]}))
%{"array" => [1, 2], "jaxon" => "rocks"}

Streaming

Jaxon can also query streams of JSON documents:

Query a binary JSON stream (notice how some items are incomplete JSON documents):

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

Query a binary JSON stream using JSON path expressions:

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

Query a large file without holding the whole file in memory:

"large_file.json"
|> File.stream!()
|> Jaxon.Stream.from_enumerable()
|> Jaxon.Stream.query([:root, "users", :all, "metadata"])
|> Stream.map(&(&1["username"],",",&1["email"],"\n"))
|> Stream.into(File.stream!("large_file.csv"))
|> Stream.run()

JSON Path

You can either write your own like so:

[:root, "users", 0, "name"]

Or use the parser:

iex> Jaxon.Path.parse!("$.array[*]")
[:root, "array", :all]
iex> Jaxon.Path.parse!(~s($["key with spaces"][0]))
[:root, "key with spaces", 0]

How does Jaxon work?

Jaxon first parses the JSON string into a list of events/tokens:

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:

:start_object
:end_object
:start_array
:end_array
{:string, binary}
{:integer, integer}
{:decimal, float}
{:boolean, boolean}
nil
{:incomplete, binary}
{:error, binary}
:colon
:comma

Which means that it can also parse a list of JSON tokens, even if the string is not a valid JSON representation:

iex> Jaxon.Parser.parse(~s("this is a string" "another string"))
[{:string, "this is a string"}, {:string, "another string"}]

This makes it very flexible when decoding files and lets us use different implementations for parsers, at the moment the default parser is written in C as a NIF. It can be changed in the config like this:

config :jaxon, :parser, Jaxon.Parsers.NifParser # only NifParser is supported at the moment

Then, the decoder's job is to take a list of events and aggregate it into a Elixir term:

iex(4)> Jaxon.Decoders.Value.decode([:start_object, {:string, "key"}, :colon, {:boolean, true}
, :end_object])
{:ok, %{"key" => true}}

About the NIF parser

All the parser does is take a binary and return a list of JSON events, the NIF respects the Erlang scheduler and tries to run for a maximum of one millisecond, yielding to the VM for another call if it runs over the limit.

Benchmarks

Jaxon (using the NIF parser) performance is similar and often faster than jiffy and jason.

To run the benchmarks, execute:

mix bench.decode

See the decode benchmarks here: benchmarks

License

Copyright © 2018 Mohamed Boudra <[email protected]>

This project is under the Apache 2.0 license. See the LICENSE file for more details.

Developed at Konbert for big data JSON parsing.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].