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

Moduleaeson-2.2.3.0Haskell2010

Data.Aeson.Encoding

Functions in this module return well-formed Encoding'. Polymorphic variants, which return Encoding a, return a textual JSON value, so it can be used as both Encoding' Text and Encoding = Encoding' Value.

  • 3 types
  • 54 values
  • Packageaeson-2.2.3.0
  • Exports57
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceEncoding.hs

Encoding

10 declarations
newtypenewtype Encoding' tag
#

An encoding of a JSON value.

tag represents which kind of JSON the Encoding is encoding to, we reuse Text and Value as tags here.

Instances14KeyValue, KeyValueOmit, SumToJSON', GToJSON', Eq, Ord, …

Make Encoding from Builder.

Use with care! You have to make sure that the passed Builder is a valid JSON Encoding!

datadata Series
#

A series of values that, when encoded, should be separated by commas. Since 0.11.0.0, the .= operator is overloaded to create either (Text, Value) or Series. You can use Series when encoding directly to a bytestring builder as in the following example:

toEncoding (Person name age) = pairs ("name" .= name <> "age" .= age)
Instances6Semigroup, Monoid, KeyValue, KeyValueOmit, KeyValuePair, FromPairs

Predicates

1 declaration

Encoding constructors

10 declarations
valuedict
  1. :: (k -> Encoding' Key)

    key encoding

  2. -> (v -> Encoding)

    value encoding

  3. -> (forall a. (k -> v -> a -> a) -> a -> m -> a)

    foldrWithKey - indexed fold

  4. -> m

    container

  5. -> Encoding
#

Encode as JSON object

Decimal numbers

valuedouble :: Double -> Encoding
#
Example1 expression
double 42"42.0"
Example1 expression
double (0/0)"null"
Example1 expression
double (1/0)"\"+inf\""
Example1 expression
double (-23/0)"\"-inf\""

Decimal numbers as Text

valuedoubleText :: Double -> Encoding' a
#
Example1 expression
doubleText 42"\"42.0\""
Example1 expression
doubleText (0/0)"\"NaN\""
Example1 expression
doubleText (1/0)"\"+inf\""
Example1 expression
doubleText (-23/0)"\"-inf\""

Time

value