aeson-t-0.0.1: 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.

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

Executing transformation

transform :: Builder -> Value -> Value Source

Generates new Aeson Value guided by a Builder