canonical_json library

This library provides a codec for encoding/decoding canonical JSON.

The canoncialJson constant provides a Codec for creating a canonical encoding of a JSON value. This library does not support floating point numbers. When decoding canonicalJson.decode will throw InvalidCanonicalJsonException if the input is not valid a canonical JSON encoding. This library is intended for scenarios where JSON values are hashed and/or signed cryptographically.

JSON as specified in RFC 8259 allows for many different encodings of the same JSON value. For example a JSON value can be encoded with:

  • an infinite combinations of insignificant whitespace,
  • unnecessary character escaping in strings,
  • scientific notation for numbers, or,
  • any ordering of object keys.

Canonical JSON is a canonicalized encoding of JSON values, such that for any JSON value that is exactly one canonical JSON encoding of said value. This library provides follows the specification used by the OLPC project, but rather than supporting arbitrary byte values as strings, strings are always encoded as UTF-8 in Unicode Normalization Form C and decoded as UTF-8 causing an InvalidCanonicalJsonException exception in case of strings not satifying this property.

Constants

canonicalJson → const Codec<Object, List<int>>
Encode/decode canonical JSON. [...]
const CanonicalJsonCodec()

Exceptions / Errors

InvalidCanonicalJsonException
Exception thrown when encountering invalid input during decoding of canonical JSON. [...]