Safe Haskell | None |
---|
Template Haskell syntax sugar for working with JSON
data.
For using this module, you need to declare a LANGUAGE pragma like the following:
{-# LANGUAGE Haskell2010, TemplateHaskell, QuasiQuotes #-}
- jsq :: QuasiQuoter
- json :: QuasiQuoter
- jsonF :: QuasiQuoter
- s :: QuasiQuoter
- sF :: QuasiQuoter
Query JSON objects
A QuasiQuoter which queries a json object using JavaScript notation.
Suppose obj contains a json object of type JSON:
[jsq| obj.prop.list[3] |]
The above will query the object in obj as if it was JavaScript.
The type of the expression is polymorphic: Convert a => a
.
You will need to specify the type of the query, like so:
[jsq| obj.prop.list |] :: [Integer]
For possible conversions, see the instances for Convert
.
Create JSON objects
A QuasiQuoter which includes JSON data.
The type of the expression is JSON
.
A QuasiQuoter which includes JSON data from files.
The following example will include the contents of data.json
as JSON
.
let str = [jsonF|data.json|]
Note that every character inside the brackets is treated
as part of the file name, that is [jsonF| data.json |]
is not
the same as the above example (it will try to find a file which
name includes space characters).
Include strings
A QuasiQuoter on raw strings.
The definition is basically:
s = QuasiQuoter { quoteExp = return . LitE . StringL }
A QuasiQuoter which includes raw strings from files.
The following example will include the contents of file.txt
as a String
.
let str = [sF|file.txt|]
Note that every character inside the brackets is treated
as part of the file name, that is [sF| file.txt |]
is not
the same as the above example (it will try to find a file which
name includes space characters).