Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
JSON quasiquoter for Haskell
Haskell
branch: master

Bump version

latest commit 36a9e0a2e1
@sol sol authored
Failed to load latest commit information.
src/Data Fix warnings
test Accept empty objects (fixes #11)
.ghci Update README
.gitignore Init commit
.travis.yml Fix warnings
LICENSE Update LICENSE, bump version
README.lhs Update README
README.markdown Update cabal file
Setup.hs Init commit
aeson-qq.cabal Bump version

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.