| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Aeson.RFC8785
Description
JSON Canonicalization Scheme https://datatracker.ietf.org/doc/html/rfc8785
Synopsis
- encodeCanonical :: ToJSON a => a -> ByteString
Documentation
encodeCanonical :: ToJSON a => a -> ByteString Source #
Encode to JSON according to RFC 8785 canonicalization scheme. https://datatracker.ietf.org/doc/html/rfc8785
encodeCanonical uses toJSON to produce intermediate Series,
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
>>>toJSON (1e23 :: Double)Number 9.999999999999999e22
show also behaves the same:
>>>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.
Since: 2.2.1.0