c14n
package included in GOBL, is inspired by the works of others and aims to define a simple standardized approach to canonical JSON that could potentially be implemented easily in other languages.
GOBL JSON C14n
GOBL considers the following JSON values as explicit types:- a string
- a number, which extends the JSON spec and is split into:
- an integer
- a float
- an object
- an array
- a boolean
- null
- MUST be encoded in VALID UTF-8. A document with invalid character encoding will be rejected.
- MUST NOT include insignificant whitespace.
- MUST order the attributes of objects lexicographically by the UCS (Unicode Character Set) code points of their names.
- MUST remove attributes from objects whose value is
null
. - MUST NOT remove null values from arrays.
- MUST represent integer numbers, those with a zero-valued fractional part, WITHOUT:
- a leading minus sign when the value is zero,
- a decimal point,
- an exponent, thus limiting numbers to 64 bits, and
- insignificant leading zeroes, as already required by JSON.
- MUST represent floating point numbers in exponential notation, INCLUDING:
- a nonzero single-digit part to the left of the decimal point,
- a nonempty fractional part to the right of the decimal point,
- no trailing zeroes to right of the decimal point except to comply with the previous point,
- a capital
E
for the exponent indicator, - no plus sign in the mantissa nor exponent, and
- no insignificant leading zeros in the exponent.
- MUST represent all strings, including object attribute keys, in their minimal length UTF-8 encoding:
- using two-character escape sequences where possible for characters that require escaping, specifically:
\"
U+0022 Quotation Mark\\
U+005C Reverse Solidus (backslash)\b
U+0008 Backspace- U+0009 Character Tabulation (tab)
- U+000A Line Feed (newline)
\f
U+000C Form Feed- U+000D Carriage Return
- using six-character
\u00XX
uppercase hexadecimal escape sequences for control characters that require escaping but lack a two-character sequence described previously, and - reject any string containing invalid encoding.
- using two-character escape sequences where possible for characters that require escaping, specifically:
encoding/json
library’s streaming methods to parse and recreate a document in memory. A simplified object model is used to map JSON structures ready to be converted into canonical JSON.