Documentation
¶
Overview ¶
Package canonical writes the canonical text of a JSON value — of a package, a module index and an open view — and stops with an error on a value the format cannot hold (format/README.md, section 25; R09). Only it writes those texts: not encoding/json, not jsontext and not the types of formatv0.
Text writes the canonical text of a tree of JSON values, and Digest and Descriptor name bytes as a package does, by sha256: and their size (R34). Its fuzz test holds Text to jsontext's Canonicalize, which lives in that test alone, in a file built only under the experiment jsonv2.
Index ¶
Constants ¶
const MaxInteger = 1<<53 - 1
MaxInteger is the largest integer that the canonical text writes, 2^53 − 1, as section 4 of format/README.md bounds an integer; the smallest is −MaxInteger.
Variables ¶
This section is empty.
Functions ¶
func Descriptor ¶
func Descriptor(data []byte) formatv0.Descriptor
Descriptor names bytes as a package does: their digest and their size.
func Digest ¶
Digest gives the digest of bytes: sha256: and their SHA-256 in 64 lowercase hexadecimal digits (format/README.md, section 25).
func Text ¶
Text gives the canonical text of a JSON value, as format/README.md, section 25, writes it — RFC 8785, which for the data of the format comes to this: the members of an object in the order of the UTF-16 code units of their names, no whitespace between tokens, an integer in decimal digits, in a string only ", \, the five short escapes and \u00XX for the rest of U+0000 to U+001F, and every other character as it is; UTF-8, with no byte order mark and no newline at the end (R09).
value is a tree of map[string]any, []any, string, int64, bool and nil, as the reader of YAML gives it once an integer that it gave as a double is an int64. Text stops with an *Error, rather than write it otherwise, at the first value it cannot hold: a float64, an integer outside ±(2^53 − 1), a string or a name that is not UTF-8, and a value of any other Go type.