Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
JSON quasiquoter for Haskell
Haskell
Branch: master
Failed to load latest commit information.
src/Data
test
.ghci Update README
.gitignore
.travis.yml
LICENSE Update LICENSE, bump version
README.lhs Update README
README.markdown
Setup.hs Init commit
aeson-qq.cabal version bump

README.markdown

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"
Something went wrong with that request. Please try again.