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

Modulehackage-security-0.6.3.2Haskell2010

Text.JSON.Canonical

Minimal implementation of Canonical JSON.

http://wiki.laptop.org/go/Canonical_JSON

A "canonical JSON" format is provided in order to provide meaningful and repeatable hashes of JSON-encoded data. Canonical JSON is parsable with any full JSON parser, but security-conscious applications will want to verify that input is in canonical form before authenticating any hash or signature on that input.

This implementation is derived from the json parser from the json package, with simplifications to meet the Canonical JSON grammar.

TODO: Known bugs/limitations:

  • Decoding/encoding Unicode code-points beyond U+00ff is currently broken

  • 2 types
  • 3 values
datadata JSValue
#
Instances6Eq, Ord, Read, Show, FromJSON, ToJSON
  • Eq JSValueDefined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Ord JSValueDefined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Read JSValueDefined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Show JSValueDefined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Monad m => FromJSON m JSValueDefined in hackage-security-0.6.3.2 · Hackage.Security.Util.JSON
  • Monad m => ToJSON m JSValueDefined in hackage-security-0.6.3.2 · Hackage.Security.Util.JSON
newtypenewtype Int54
#

54-bit integer values

JavaScript can only safely represent numbers between -(2^53 - 1) and 2^53 - 1.

TODO: Although we introduce the type here, we don't actually do any bounds checking and just inherit all type class instance from Int64. We should probably define fromInteger to do bounds checking, give different instances for type classes such as Bounded and FiniteBits, etc.

Instances17Bounded, Enum, Eq, Integral, Data, Num, …
  • Bounded Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Enum Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Eq Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Integral Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Data Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Num Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Ord Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Read Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Real Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Show Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Ix Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Bits Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • FiniteBits Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • Storable Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • PrintfArg Int54Defined in hackage-security-0.6.3.2 · Text.JSON.Canonical
  • ReportSchemaErrors m => FromJSON m Int54Defined in hackage-security-0.6.3.2 · Hackage.Security.Util.JSON
  • Monad m => ToJSON m Int54Defined in hackage-security-0.6.3.2 · Hackage.Security.Util.JSON

Render a JSON value in canonical form. This rendered form is canonical and so allows repeatable hashes.

For pretty printing, see prettyCanonicalJSON.

NB: Canonical JSON's string escaping rules deviate from RFC 7159 JSON which requires

"All Unicode characters may be placed within the quotation marks, except for the characters that must be escaped: quotation mark, reverse solidus, and the control characters (U+0000 through U+001F)."

Whereas the current specification of Canonical JSON explicitly requires to violate this by only escaping the quotation mark and the reverse solidus. This, however, contradicts Canonical JSON's statement that "Canonical JSON is parsable with any full JSON parser"

Consequently, Canonical JSON is not a proper subset of RFC 7159.