HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Modulemicrolens-aeson-2.5.2Haskell2010

Lens.Micro.Aeson

Traversals for Data.Aeson, based on microlens for minimal dependencies.

For basic manipulation of Aeson values, full Prism functionality isn't necessary. Since all Prisms are inherently Traversals, we provide Traversals that mimic the behaviour of the Prisms found in the original Data.Aeson.Lens.

Contents
  1. Numbers
  2. Objects and Arrays
  3. Decoding
Synopsis

Numbers

classclass AsNumber t where

Traverse into various number types.

Methods

Instances7AsNumber, …

Traversal into non-Null values

Example1 expression
"{\"a\": \"xyz\", \"b\": null}" ^? key "a" . nonNullJust (String "xyz")
Example1 expression
"{\"a\": {}, \"b\": null}" ^? key "a" . nonNullJust (Object (fromList []))
Example1 expression
"{\"a\": \"xyz\", \"b\": null}" ^? key "b" . nonNullNothing

Objects and Arrays

classclass AsNumber t => AsValue t where

Traverse into JSON Objects and Arrays.

Methods

  • _Value :: Traversal' t Value

    Traverse into data that encodes a Value

  • _String :: Traversal' t Text
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "a" . _StringJust "xyz"
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "b" . _StringNothing
  • _Bool :: Traversal' t Bool
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "b" . _BoolJust True
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "a" . _BoolNothing
  • _Null :: Traversal' t ()
    Example1 expression
    "{\"a\": \"xyz\", \"b\": null}" ^? key "b" . _NullJust ()
    Example1 expression
    "{\"a\": \"xyz\", \"b\": null}" ^? key "a" . _NullNothing
  • _Object :: Traversal' t (KeyMap Value)
    Example1 expression
    "{\"a\": {}, \"b\": null}" ^? key "a" . _ObjectJust (fromList [])
    Example1 expression
    "{\"a\": {}, \"b\": null}" ^? key "b" . _ObjectNothing
  • _Array :: Traversal' t (Vector Value)
Instances6AsValue
valuekey :: AsValue t => Key -> Traversal' t Value

Like ix, but for Object with Key indices. This often has better inference than ix when used with OverloadedStrings.

Example1 expression
"{\"a\": 100, \"b\": 200}" ^? key "a"Just (Number 100.0)
Example1 expression
"[1,2,3]" ^? key "a"Nothing

A Traversal into Object properties

Example1 expression
"{\"a\": 4, \"b\": 7}" ^.. members[Number 4.0,Number 7.0]
Example1 expression
"{\"a\": 4, \"b\": 7}" & members . _Number %~ (* 10)"{\"a\":40,\"b\":70}"
valuenth :: AsValue t => Int -> Traversal' t Value

Like ix, but for Arrays with Int indexes

Example1 expression
"[1,2,3]" ^? nth 1Just (Number 2.0)
Example1 expression
"{\"a\": 100, \"b\": 200}" ^? nth 1Nothing
Example1 expression
"[1,2,3]" & nth 1 .~ Number 20"[1,20,3]"

A Traversal into Array elements

Example1 expression
"[1,2,3]" ^.. values[Number 1.0,Number 2.0,Number 3.0]
Example1 expression
"[1,2,3]" & values . _Number %~ (* 10)"[10,20,30]"

Decoding

classclass AsJSON t where

Traverse into actual encoded JSON.

Methods

Instances6AsJSON
  • AsJSON ValueDefined in microlens-aeson-2.5.2 · Lens.Micro.Aeson
  • AsJSON ByteStringDefined in microlens-aeson-2.5.2 · Lens.Micro.Aeson
  • AsJSON ByteStringDefined in microlens-aeson-2.5.2 · Lens.Micro.Aeson
  • AsJSON StringDefined in microlens-aeson-2.5.2 · Lens.Micro.Aeson
  • AsJSON TextDefined in microlens-aeson-2.5.2 · Lens.Micro.Aeson
  • AsJSON TextDefined in microlens-aeson-2.5.2 · Lens.Micro.Aeson