Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sol/aeson-qq
JSON quasiquoter for Haskell
https://github.com/sol/aeson-qq
Last synced: 27 days ago
JSON representation
JSON quasiquoter for Haskell
- Host: GitHub
- URL: https://github.com/sol/aeson-qq
- Owner: sol
- License: mit
- Created: 2011-04-16T14:29:44.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2023-05-21T12:45:15.000Z (over 1 year ago)
- Last Synced: 2024-10-29T22:00:30.403Z (about 2 months ago)
- Language: Haskell
- Homepage: http://hackage.haskell.org/package/aeson-qq
- Size: 52.7 KB
- Stars: 80
- Watchers: 40
- Forks: 14
- Open Issues: 3
-
Metadata Files:
- Readme: README.lhs
- License: LICENSE
Awesome Lists containing this project
- awesome-json - aeson-qq - JSON quasiquoter for Haskell. (Libraries)
README
# aeson-qq: JSON quasiquoter for Haskell
This package exposes the function
[`aesonQQ`](http://hackage.haskell.org/package/aeson-qq/docs/Data-Aeson-QQ.html#v:aesonQQ)
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 ignore
aesonQQ :: QuasiQuoter
```and is used like
```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
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
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
joe :: Value
joe = [aesonQQ| {$key: 23, name: "Joe"} |]
where
key = "age"
```