dead-simple-json-0.1.2: Dead simple JSON parser, with some Template Haskell sugar.

Safe HaskellNone

Text.DeadSimpleJSON.TH

Contents

Description

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 #-}

Synopsis

Query JSON objects

jsq :: QuasiQuoterSource

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

json :: QuasiQuoterSource

A QuasiQuoter which includes JSON data.

The type of the expression is JSON.

jsonF :: QuasiQuoterSource

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

s :: QuasiQuoterSource

A QuasiQuoter on raw strings.

The definition is basically:

 s = QuasiQuoter {
   quoteExp  = return . LitE . StringL
 }

sF :: QuasiQuoterSource

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).