HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulelens-aeson-1.2.3Haskell2010

Data.Aeson.Lens

This module also exports orphan Ixed Value and Plated Value instances.

  • 4 classes
  • 8 values

Numbers

3 declarations
classclass AsNumber t where
#

Methods

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

Access Integer Values as Integrals.

Example1 expression
"[10]" ^? nth 0 . _IntegralJust 10
Example1 expression
"[10.5]" ^? nth 0 . _IntegralJust 10
valuenonNull :: Prism' Value Value
#

Prism 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

7 declarations
classclass AsNumber t => AsValue t where
#

Methods

  • _Value :: Prism' t Value
    Example1 expression
    preview _Value "[1,2,3]" == Just (Array (Vector.fromList [Number 1.0,Number 2.0,Number 3.0]))True
  • _String :: Prism' t Text
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "a" . _StringJust "xyz"
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "b" . _StringNothing
    Example1 expression
    _Object._Wrapped # [("key" :: Key, _String # "value")] :: String"{\"key\":\"value\"}"
  • _Bool :: Prism' t Bool
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "b" . _BoolJust True
    Example1 expression
    "{\"a\": \"xyz\", \"b\": true}" ^? key "a" . _BoolNothing
    Example1 expression
    _Bool # True :: String"true"
    Example1 expression
    _Bool # False :: String"false"
  • _Null :: Prism' t ()
    Example1 expression
    "{\"a\": \"xyz\", \"b\": null}" ^? key "b" . _NullJust ()
    Example1 expression
    "{\"a\": \"xyz\", \"b\": null}" ^? key "a" . _NullNothing
    Example1 expression
    _Null # () :: String"null"
  • _Object :: Prism' t (KeyMap Value)
    Example1 expression
    "{\"a\": {}, \"b\": null}" ^? key "a" . _ObjectJust (fromList [])
    Example1 expression
    "{\"a\": {}, \"b\": null}" ^? key "b" . _ObjectNothing
    Example1 expression
    _Object._Wrapped # [("key" :: Key, _String # "value")] :: String"{\"key\":\"value\"}"
  • _Array :: Prism' t (Vector Value)
    Example1 expression
    preview _Array "[1,2,3]" == Just (Vector.fromList [Number 1.0,Number 2.0,Number 3.0])True
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
valueatKey :: AsValue t => Key -> Traversal' t (Maybe Value)
#

Like key, but uses at instead of ix. This is handy when adding and removing object keys:

Example1 expression
"{\"a\": 100, \"b\": 200}" & atKey "a" .~ Nothing"{\"b\":200}"
Example1 expression
"{\"a\": 100, \"b\": 200}" & atKey "c" ?~ String "300""{\"a\":100,\"b\":200,\"c\":\"300\"}"

An indexed Traversal into Object properties

Example1 expression
Data.List.sort ("{\"a\": 4, \"b\": 7}" ^@.. members . _Number)[("a",4.0),("b",7.0)]
Example1 expression
"{\"a\": 4}" & members . _Number *~ 10"{\"a\":40}"
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]"

An indexed 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]"
classclass IsKey t where
#

Methods

  • _Key :: Iso' t Key

    _Key is an Iso from something to a Key. This is primarily intended for situations where one wishes to use object keys that are not string literals and therefore must be converted:

    Example2 expressions
    let k = "a" :: Text"{\"a\": 100, \"b\": 200}" ^? key (k ^. _Key)Just (Number 100.0)

    Note that applying _Key directly to a string literal (e.g., "a" ^. _Key) will likely not typecheck when OverloadedStrings is enabled.

Instances7IsKey, …
  • IsKey KeyDefined in lens-aeson-1.2.3 · Data.Aeson.Lens
  • IsKey ByteStringDefined in lens-aeson-1.2.3 · Data.Aeson.Lens

    This instance assumes that you are dealing with UTF-8–encoded ByteStrings, as this is the encoding that RFC 8259 requires JSON values to use. As such, this is not a full Iso, since non–UTF-8–encoded ByteStrings will not roundtrip:

    Example3 expressions
    let str = view _Key ("\255" :: Strict.ByteString)str"\65533"view (from _Key) str :: Strict.ByteString"\239\191\189"
  • IsKey ByteStringDefined in lens-aeson-1.2.3 · Data.Aeson.Lens

    This instance assumes that you are dealing with UTF-8–encoded ByteStrings, as this is the encoding that RFC 8259 requires JSON values to use. As such, this is not a full Iso, since non–UTF-8–encoded ByteStrings will not roundtrip:

    Example3 expressions
    let str = view _Key ("\255" :: Lazy.ByteString)str"\65533"view (from _Key) str :: Lazy.ByteString"\239\191\189"
  • IsKey StringDefined in lens-aeson-1.2.3 · Data.Aeson.Lens
  • IsKey TextDefined in lens-aeson-1.2.3 · Data.Aeson.Lens
  • IsKey TextDefined in lens-aeson-1.2.3 · Data.Aeson.Lens
  • IsKey ShortTextDefined in lens-aeson-1.2.3 · Data.Aeson.Lens

Decoding

2 declarations
classclass AsJSON t where
#

Methods

Instances6AsJSON

Pattern Synonyms

10 declarations

Orphan instances

7 instances