highjson: Very fast JSON parsing

[ json, library, mit, text, web ] [ Propose Tags ]

Low boilerplate, easy to use and very fast JSON parsing


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.2.0.1, 0.2.0.2, 0.3.0.0, 0.4.0.0, 0.5.0.0 (info)
Dependencies attoparsec (>=0.13.0.0), base (>=4.7 && <5), bytestring (>=0.10.4.0), containers, hashable (>=1.1.2), hvect (>=0.2), scientific (>=0.3.3), text (>=1.1.1), unordered-containers (>=0.2.5), vector (>=0.7.1) [details]
License MIT
Copyright (c) 2015 Alexander Thiemann
Author Alexander Thiemann <mail@athiemann.net>
Maintainer Alexander Thiemann <mail@athiemann.net>
Category Text, Web, JSON
Home page https://github.com/agrafix/highjson
Bug tracker https://github.com/agrafix/highjson/issues
Source repo head: git clone git://github.com/agrafix/highjson.git
Uploaded by AlexanderThiemann at 2015-07-19T21:40:59Z
Distributions
Reverse Dependencies 2 direct, 1 indirect [details]
Downloads 4337 total (22 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-07-19 [all 1 reports]

Readme for highjson-0.1.0.0

[back to package description]

highjson

Build Status

Hackage Deps

Intro

Hackage: highjson

Low boilerplate, easy to use and very fast Haskell JSON parsing. WARNING: Work in progress!

Usage

{-# LANGUAGE OverloadedStrings #-}
import Data.Json.Parser

data SomeDummy
   = SomeDummy
   { sd_int :: Int
   , sd_bool :: Bool
   , sd_text :: T.Text
   , sd_either :: Either Bool T.Text
   , sd_maybe :: Maybe Int
   } deriving (Show, Eq)

instance JsonReadable SomeDummy where
    readJson =
       runSpec SomeDummy $
          "int" :&&: "bool" :&&: "text" :&&: "either" :&&: "maybe" :&&: ObjSpecNil

test =
    parseJsonBs "{\"int\": 34, \"text\": \"Teext\", \"bool\": true, \"either\": false}"
                               == Right (SomeDummy 34 True "Teext" (Left False) Nothing)

Install

  • Using cabal: cabal install highjson
  • From Source: git clone https://github.com/agrafix/highjson.git && cd highjson && cabal install

Todo

  • Implement proper string parsing (handle escape charaters)
  • Write more tests
  • Allow fast json generation via object specs
  • Generate typescript interfaces from object specs
  • ...

Benchmarks

To run the benchmarks, use cabal bench. Current results on my MacBook Pro:

$ cabal bench
Preprocessing library highjson-0.1.0.0...
[1 of 1] Compiling Data.Json.Parser ( src/Data/Json/Parser.hs, dist/build/Data/Json/Parser.o )
In-place registering highjson-0.1.0.0...
Preprocessing benchmark 'highjson-benchmarks' for highjson-0.1.0.0...
[1 of 1] Compiling Main             ( bench/Twitter.hs, dist/build/highjson-benchmarks/highjson-benchmarks-tmp/Main.o ) [Data.Json.Parser changed]
Linking dist/build/highjson-benchmarks/highjson-benchmarks ...
Running 1 benchmarks...
Benchmark highjson-benchmarks: RUNNING...
benchmarking twitter/aeson
time                 2.200 ms   (2.044 ms .. 2.349 ms)
                     0.983 R²   (0.975 R² .. 0.996 R²)
mean                 2.065 ms   (2.031 ms .. 2.120 ms)
std dev              138.3 μs   (93.40 μs .. 204.8 μs)
variance introduced by outliers: 48% (moderately inflated)

benchmarking twitter/highjson
time                 2.058 ms   (2.032 ms .. 2.087 ms)
                     0.997 R²   (0.994 R² .. 0.999 R²)
mean                 2.077 ms   (2.050 ms .. 2.115 ms)
std dev              103.6 μs   (80.86 μs .. 138.0 μs)
variance introduced by outliers: 35% (moderately inflated)

The benchmarks are derived from aeson's twitter-json-parsing benchmarks and should probably more there when this library is in a more complete state.