text-json-qq-0.4.1: Json Quasiquatation for Haskell.



This package expose the function jsonQQ that compile time converts json code into a Text.JSON.JSValue. jsonQQ got the signature

 jsonQQ :: QuasiQuoter

and is used like

 myCode = [jsonQQ| {age: 23, name: "Pelle", likes: ["mac","Haskell"] } |]

where it is important that

  • you got no space in [jsonQQ| and
  • no additional code after |].

The quasiquatation can also bind to variables like

 myCode = [jsonQQ| {age: <|age|>, name: <|name|>} |]
 where age = 34 :: Integer
       name = "Pelle"

where the function toJSON will be called on age and name runtime.

You can also insert Haskell code:

 myCode = [jsonQQ| {age: <|age + 34 :: Integer|>, name: <|map toUpper name|>} |]
 where age = 34 :: Integer
       name = "Pelle"

You can use a similar syntax if you want to insert a value of type JSValue like

 myCode = [jsonQQ| {"age": <<age>>} |]

If you want to replace the name of the key in a hash you'll use the $-syntax:

 foo = [jsonQQ| {$bar: 42} |]
 bar = "age"