Quickson-0.2: Quick JSON extractions with Aeson

Safe HaskellNone




How to use this library

Quickson exports a function quickson which enables you to perform quick extractions of JSON data using Aeson.

Aeson's type machinery allows decoding of complex data structures using just the decode function, however, JSON object lookups cannot be encoded using the type system alone. Quickson helps by doing the lookups for you so that the type system can do the rest. For example, say you have a JSON document as such:

{ "name": "bob", "age": 25, "hobbies": [{"name": "Tennis"}] }

And you'd like to turn this into a `(String, Maybe Int, [String])` with minimal fuss:

>>> type Hobbyist = (String, Maybe Int, [String])
>>> let eitherResult = quickson "{name,age?,hobbies:[{name}]}" jsonDoc :: Either String Hobbyist
Right ("bob",Just 25,["Tennis"])

So the structure specification is just to remove the objects so that the type system can do the rest.


  • Top level objects must be [] or {}
  • Lookup: {key}
  • Optional lookup: {key?} (yielding Maybe a)
  • List: []

data Quickson Source

Quickson intermediary representation


Ob [(Text, Bool, Quickson)] 
Li Quickson 


quicksonParse :: ByteString -> Either String Quickson Source

Parse a quickson structure

quicksonExecute :: FromJSON a => Quickson -> Value -> Either String a Source

Execute a quickson structure against a value

quickson :: FromJSON a => ByteString -> ByteString -> Either String a Source

Perform a JSON extraction, returning either an error description or a parsed data structure