HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

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.

  • 3 classes
  • 6 values

Numbers

3 declarations
classclass AsNumber t where
#

Traverse into various number types.

Methods

Instances7AsNumber, …
value_Integral :: (AsNumber t, Integral a) => Traversal' t a
#

Access Integer Values as Integrals.

Example1 expression
"[10]" ^? nth 0 . _IntegralJust 10
Example1 expression
"[10.5]" ^? nth 0 . _IntegralJust 10

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

5 declarations
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
valuemembers :: AsValue t => Traversal' t Value
#

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]"
valuevalues :: AsValue t => Traversal' t Value
#

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

1 declaration
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