| Safe Haskell | None | 
|---|---|
| Language | Haskell2010 | 
Data.Aeson.Transform
Contents
Example usage
Filter unwanted attributes from an object
keep ["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 -- [[1,2], [3,4]] => [1, 3]
Create object
obj $ fromList [
    ("first", index 0)
  , ("second", index 1)
  ]
-- ["hi", "bye"] => { first:"hi", second:"bye" }Transform position
at "ranks" $ atIndex 0 $ attr "name"
-- {ranks: [ { name:"winner", score:12 }, { name:"loser", score: 3 ]}
-- => "winner"Combine objects
merge (attr "foo") (attr "bar")
-- { foo: { a:1, b:2 }, bar: { b:3, c:4 } }
-- => { a:1, b:2, c:4 }