All Projects → michalmuskala → Jason

michalmuskala / Jason

Licence: other
A blazing fast JSON parser and generator in pure Elixir.

Programming Languages

elixir
2628 projects

Labels

Projects that are alternatives of or similar to Jason

Magento2 Import Export Sample Files
Default Magento 2 CE import / export CSV files & sample files for Firebear Improved Import / Export extension
Stars: ✭ 68 (-94.21%)
Mutual labels:  json
Avocado
Strongly-typed MongoDB driver for Rust
Stars: ✭ 70 (-94.04%)
Mutual labels:  json
Metajson
Non-intrusive, high performance C++17 lightweight JSON de/serializer
Stars: ✭ 71 (-93.95%)
Mutual labels:  json
Utils
🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
Stars: ✭ 1,158 (-1.36%)
Mutual labels:  json
Jquery Jsontotable
This plugin can convert JSON data type to table for html. JSON is used primarily to transmit data between a server and web application, as an alternative to XML. In these reasons todays many applications use json data format for data transferring. And you need json to table converter for html display.
Stars: ✭ 69 (-94.12%)
Mutual labels:  json
Jsoncsharpclassgenerator
JsonCSharpClassGenerator from http://jsonclassgenerator.codeplex.com/
Stars: ✭ 70 (-94.04%)
Mutual labels:  json
Null
reasonable handling of nullable values
Stars: ✭ 1,148 (-2.21%)
Mutual labels:  json
Ducky
Duck-Typed Value Handling for JavaScript
Stars: ✭ 71 (-93.95%)
Mutual labels:  json
Randomjson
Provides a Kotlin/Java library to create a random json string
Stars: ✭ 70 (-94.04%)
Mutual labels:  json
Fipe Json
🚘 FIPE API - Listagem com preço médio de veículos: carro, moto e caminhão.
Stars: ✭ 71 (-93.95%)
Mutual labels:  json
Json Rules Engine
A rules engine expressed in JSON
Stars: ✭ 1,159 (-1.28%)
Mutual labels:  json
Fastjson
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection
Stars: ✭ 1,164 (-0.85%)
Mutual labels:  json
Zio Tls Http
100% non-blocking, Java NIO only( inspired by zio-nio) , JSON HTTP server based on Scala ZIO library. Everything including TLS encryption modeled as ZIO effects, convenient route DSL similar to https4s, up to 30K TPS local JSON transaction with 25 threads on 6 cores(i7) with ZIO fibers.
Stars: ✭ 71 (-93.95%)
Mutual labels:  json
Servicestack.text
.NET's fastest JSON, JSV and CSV Text Serializers
Stars: ✭ 1,157 (-1.45%)
Mutual labels:  json
React Json Graph
React component for rendering graphs
Stars: ✭ 71 (-93.95%)
Mutual labels:  json
Httpz
purely functional http client with scalaz.Free
Stars: ✭ 67 (-94.29%)
Mutual labels:  json
Elm Json Tree View
A library for Elm that shows JSON data as an expandable HTML tree
Stars: ✭ 70 (-94.04%)
Mutual labels:  json
Covid19
JSON time-series of coronavirus cases (confirmed, deaths and recovered) per country - updated daily
Stars: ✭ 1,177 (+0.26%)
Mutual labels:  json
Rest
☕ REST: Yoctoframework — https://rest.n2o.dev
Stars: ✭ 71 (-93.95%)
Mutual labels:  json
Jokeapi
A REST API that serves uniformly and well formatted jokes in JSON, XML, YAML or plain text format that also offers a great variety of filtering methods
Stars: ✭ 71 (-93.95%)
Mutual labels:  json

Jason

A blazing fast JSON parser and generator in pure Elixir.

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

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

Installation

The package can be installed by adding jason to your list of dependencies in mix.exs:

def deps do
  [{:jason, "~> 1.2"}]
end

Basic Usage

iex(1)> Jason.encode!(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"})
"{\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}"

iex(2)> Jason.decode!(~s({"age":44,"name":"Steve Irwin","nationality":"Australian"}))
%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"}

Full documentation can be found at https://hexdocs.pm/jason.

Use with other libraries

Postgrex

Versions starting at 0.14.0 use Jason by default. For earlier versions, please refer to previous versions of this document.

Ecto

Versions starting at 3.0.0 use Jason by default. For earlier versions, please refer to previous versions of this document.

Plug (and Phoenix)

Phoenix starting at 1.4.0 uses Jason by default. For earlier versions, please refer to previous versions of this document.

Absinthe

You need to pass the :json_codec option to Absinthe.Plug

# When called directly:
plug Absinthe.Plug,
  schema: MyApp.Schema,
  json_codec: Jason

# When used in phoenix router:
forward "/api",
  to: Absinthe.Plug,
  init_opts: [schema: MyApp.Schema, json_codec: Jason]

Benchmarks

Detailed benchmarks (including memory measurements): https://gist.github.com/michalmuskala/4d64a5a7696ca84ac7c169a0206640d5

HTML reports for the benchmark (only performance measurements): http://michal.muskala.eu/jason/decode.html and http://michal.muskala.eu/jason/encode.html

Running

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 Poison

Jason has a couple feature differences compared to Poison.

  • Jason follows the JSON spec more strictly, for example it does not allow unescaped newline characters in JSON strings - e.g. "\"\n\"" will produce a decoding error.
  • no support for decoding into data structures (the as: option).
  • no built-in encoders for MapSet, Range and Stream.
  • no support for encoding arbitrary structs - explicit implementation of the Jason.Encoder protocol is always required.
  • different pretty-printing customisation options (default pretty: true works the same)

If you require encoders for any of the unsupported collection types, I suggest adding the needed implementations directly to your project:

defimpl Jason.Encoder, for: [MapSet, Range, Stream] do
  def encode(struct, opts) do
    Jason.Encode.list(Enum.to_list(struct), opts)
  end
end

If you need to encode some struct that does not implement the protocol, if you own the struct, you can derive the implementation specifying which fields should be encoded to JSON:

@derive {Jason.Encoder, only: [....]}
defstruct # ...

It is also possible to encode all fields, although this should be used carefully to avoid accidentally leaking private information when new fields are added:

@derive Jason.Encoder
defstruct # ...

Finally, if you don't own the struct you want to encode to JSON, you may use Protocol.derive/3 placed outside of any module:

Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
Protocol.derive(Jason.Encoder, NameOfTheStruct)

License

Jason is released under the Apache License 2.0 - see the LICENSE file.

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

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].