| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Aeson.Transform
Example usage
Filter unwanted attributes from an object
Attrs ["nice", "good"]
-- { bad: 3, good: 1, nice: 500, evil: -3 }
-- => { good: 1, nice: 500 }Grab value
Attr "foo"
-- { foo: 2 } => 2Dig deeper
At "foo" $ Attr "bar"
-- { foo: { bar: 3 }} => 3Map stuff
Map $ Attr "foo"
-- [{ foo:1, foo:2 }] => [1, 2]Extract indices
Map $ Index 0 Id -- [[1,2], [3,4]] => [1, 3]
Create object
Obj $ fromList [
("first", Index 0 Id)
, ("second", Index 1 Id)
]
-- ["hi", "bye"] => { first:"hi", second:"bye" }Transformation builder
Transformations are specified by creating Builder instances.
Builders specify how to navigate through input JSON and construct
output at various nodes in the tree.
Constructors
| Id | Pass input directly as output |
| At Text Builder | Move to value in current object |
| Attr Text | Get value in current object |
| Attrs [Text] | Filter current object by keys |
| Map Builder | Map over input array |
| Index Int Builder | Get value at index of current array |
| Obj (HashMap Text Builder) | Produce object with given keys |