| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Aeson.Quick
- (.?) :: FromJSON a => Value -> Structure -> Maybe a
- (.!) :: FromJSON a => Value -> Structure -> a
- extract :: FromJSON a => Structure -> Value -> Parser a
- (.%) :: ToJSON a => Structure -> a -> Value
- build :: ToJSON a => Structure -> Value -> a -> Value
- data Structure
- parseStructure :: Text -> Either String Structure
Documentation
aeson-quick is a library for terse marshalling of data to and from aeson's
Value.
It works on the observation that by turning objects into tuples inside
the Value, the type system can be employed to do more of the work.
For example, given the JSON:
{ "name": "bob"
, "age": 29
, "hobbies": [{"name": "tennis"}, {"name": "cooking"}]
}You can write:
extractHobbyist ::Value->Maybe(String,Int, [String]) extractHobbyist value = value.?"{name,age,hobbies:[{name}]}"
(.?) :: FromJSON a => Value -> Structure -> Maybe a Source #
Extracts instances of FromJSON from a Value
This is a wrapper around extract which does the actual work.
Examples assume FromJSON Foo and FromJSON Bar.
Extract key from object:
>>>"{key}" .? value :: Maybe Foo
Extract list of objects:
>>>"[{key}]" .? value :: Maybe [Foo]
Extract with optional key:
>>>"{key,opt?}" .? value :: Maybe (Foo, Maybe Bar)
(.!) :: FromJSON a => Value -> Structure -> a Source #
The (very!) unsafe version of .?. This can fail very easily, do not depend on this in your program. Will probably be removed.
(.%) :: ToJSON a => Structure -> a -> Value Source #
Turns data into JSON objects.
This is a wrapper around build which does the actual work.
Build a simple Value:
>>>encode $ "{a}" .% True{\"a\": True}
Build a complex Value:
>>>encode $ "[{a}]" '.%' [True, False]"[{\"a\":true},{\"a\":false}]"