Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed May 31, 2017
1 parent cb81776 commit 78ebf99
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,49 @@ that compile-time converts a string representation of a JSON value into a
[`Data.Aeson.Value`](http://hackage.haskell.org/package/aeson-0.7.0.6/docs/Data-Aeson.html#t:Value).
`aesonQQ` has the signature

```haskell
```haskell ignore
aesonQQ :: QuasiQuoter
```

and is used like

~~~ {.haskell}
```haskell
{-# 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

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

where the function
[`toJSON`](http://hackage.haskell.org/package/aeson-0.7.0.6/docs/Data-Aeson.html#v:toJSON).
will be called on `age` and `name` at runtime.

You can also interpolate arbitrary Haskell expressions:

~~~ {.haskell}
```haskell
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:

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

0 comments on commit 78ebf99

Please sign in to comment.