aeson-t-0.0.0: Transform JSON

Safe HaskellNone
LanguageHaskell2010

Data.Aeson.Transform

Contents

Synopsis

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 } => 2

Dig deeper

At "foo" $ Attr "bar"

-- { foo: { bar: 3 }} => 3

Map 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

data Builder Source

Transformations are specified by creating Builder instances. Builders specify how to navigate through input JSON and construct output at various nodes in the tree.

Executing transformation

transform :: Builder -> Value -> Value Source

Generates new Aeson Value guided by a Builder