JSON quasiquoter for Haskell


Keywords
library, mit, Propose Tags, https://github.com/sol/aeson-qq#readme, , Index, Quick Jump, Data.Aeson.QQ, aeson-qq-0.8.4.tar.gz, browse, Package description, Package maintainers, OscarFinnsson, SimonHengel, edit package information , 0.8.4
License
MIT
Install
cabal install aeson-qq-0.8.4

Documentation

aeson-qq: JSON quasiquoter for Haskell

This package exposes the function aesonQQ that compile-time converts a string representation of a JSON value into a Data.Aeson.Value. aesonQQ has the signature

aesonQQ :: QuasiQuoter

and is used like

{-# LANGUAGE QuasiQuotes #-}
import Data.Aeson.QQ
import Data.Aeson (Value)

john :: Value
john = [aesonQQ| {age: 23, name: "John", likes: ["linux", "Haskell"]} |]

The quasiquoter can also interpolate variables like

jane :: Value
jane = [aesonQQ| {age: #{age}, name: #{name}} |]
  where
    age = 23 :: Int
    name = "Jane"

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

You can also interpolate arbitrary Haskell expressions:

mary :: Value
mary = [aesonQQ| {age: #{succ age}, name: "Mary"} |]
  where
    age = 23 :: Int

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

joe :: Value
joe = [aesonQQ| {$key: 23, name: "Joe"} |]
  where
    key = "age"