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

Moduleaeson-2.2.3.0Haskell2010

Data.Aeson.RFC8785

  • 1 value
  • Packageaeson-2.2.3.0
  • Exports1
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceRFC8785.hs
valueencodeCanonical :: ToJSON a => a -> ByteString
#

Encode to JSON according to RFC 8785 canonicalization scheme. https://datatracker.ietf.org/doc/html/rfc8785

encodeCanonical uses toJSON to produce intermediate Value, as toEncoding may (and most likely) produces non-canonical JSON.

Note: decode (encodeCanonical v) === Just v for all v :: Value, i.e. encodeCanonical doesn't lose any information.

However, the example in RFC8785 loses information as the intermediate number representation is Double, also current toJSON :: Double -> Value sometimes produces too precise values. For example

Example1 expression
toJSON (1e23 :: Double)Number 9.999999999999999e22

show also behaves the same:

Example1 expression
1e23 :: Double9.999999999999999e22

Note: RFC8785 is not the same scheme as used in canonical-json package (https:/wiki.laptop.orggo/Canonical_JSON). That scheme produces invalid JSON (e.g. control characters encoded as is, not escaped) and cannot encode non-integral numbers.