canonical-json-0.6.0.0: Canonical JSON for signing and hashing JSON values

Copyright(c) Galois Inc. 2007-2009 Duncan Coutts 2015 2017
Safe HaskellNone
LanguageHaskell2010

Text.JSON.Canonical.Parse

Description

Minimal implementation of Canonical JSON parsing and printing.

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

TODO: Known bugs/limitations:

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

Documentation

parseCanonicalJSON :: ByteString -> Either String JSValue Source #

Parse a canonical JSON format string as a JSON value. The input string does not have to be in canonical form, just in the "canonical JSON" format.

Use renderCanonicalJSON to convert into canonical form.

renderCanonicalJSON :: JSValue -> ByteString Source #

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.

prettyCanonicalJSON :: JSValue -> String Source #

Render a JSON value in a reasonable human-readable form. This rendered form is not the canonical form used for repeatable hashes, use renderCanonicalJSON for that.