MyNixOS website logo
Description

Fast JSON parsing powered by Chad Austin's sajson library.

A fast JSON parsing library that is faster than aeson.

sajson

This is a Haskell package that is a thin wrapper over the wonderful sajson library written by Chad Austin. It provides a high performance JSON parser written in C++11. After parsing, a Haskell Data.Aeson.Value is constructed.

Who This Is For

This library is specifically designed for Haskell users who find the performance of the pure-Haskell Data.Aeson parser inadequate. This library focuses on performance, not portability or absolute correctness. You should only use this library if all of the following is true:

  • You are using a system that is 64-bit. This library assumes sizeof(size_t) == 8. If this is not the case, the behavior is undefined.

  • You are using a system where the alignment of double is no stricter than that of size_t. Internally, the library casts a pointer to size_t into a pointer to double and expects this to be meaningful.

  • You do not expect to parse floating point numbers beyond the range of double.

  • You do not expect to parse integers that are longer than 53 bits.

  • You do not expect parsing a JSON number will produce a Haskell Scientific value that exactly represents the mathematical value of the JSON number, or even the closest approximation in IEEE-754 double.

    For example if you parse numbers that would be denormal numbers in IEEE-754 double-precision numbers, you will very likely get back zero instead.

    As another example, if you parse 0.3, which cannot be represented exactly in IEEE-754 double, you will get back 0.30000000000000004, instead of the closest number in IEEE-754 double which is 0.29999999999999999.

  • You wish to sacrifice memory consumption for speed. The intermediate memory needed is 9 times the number of bytes of the input ByteString plus constant. This excludes the memory needed by the parsed Value or the memory of the input ByteString.

  • You are parsing JSON that is known to be valid. As a library written in C++, it is inherently unsafe. Despite the use of address sanitizer and AFL which have caught memory usage bugs, it is difficult to guarantee that creatively crafted input will not crash or cause arbitrary code execution. It is recommend that you use this library only for parsing known good JSON.

If you satisfy all of the above, then this library could work for you. Again, please benchmark and show that JSON parsing is indeed a bottleneck before using this library.

Ideas and Future Plan

  • Skip creating Values when the you eventually want another Haskell type. Currently the FromJSON instance needs a Value, but perhaps we can devise another method to avoid the generation of these intermediate Values.

  • Provide a benchmark so that we can quantitatively argue this library parses JSON faster than Data.Aeson.

  • Provide an alternative for parsing floating point numbers that better preserves the value.

  • More complete tests, including QuickCheck-based tests.

Metadata

Version

0.2.0.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows