aeson-qq-0.4.1: Json Quasiquatation for Haskell.



This package expose the function aesonQQ that compile time converts json code into a Data.Aeson.Value. aesonQQ got the signature

 aesonQQ :: QuasiQuoter

and is used like

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

where it is important that

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

The quasiquatation can also bind to variables like

 myCode = [aesonQQ| {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 = [aesonQQ| {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 Data.Aeson.Value like

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

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

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