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. Only it writes those texts: not encoding/json, not jsontext and not the types of formatv0.
Digest and Descriptor name bytes as a package does, by sha256: and their size. Parse reads a JSON text into the tree Text takes, an integer as an int64. The fuzz test holds Text to jsontext's Canonicalize, which only that test imports, 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, the bound of an integer of the format; 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.
func Parse ¶ added in v0.1.22
Parse reads a JSON text into the tree of JSON values that Text takes, as the reader of YAML gives one: a number written with neither a fraction nor an exponent as an int64, when it fits one, and any other number as a float64, which Text then refuses. A text with anything after its value is no JSON text, and neither is one that is not UTF-8, which encoding/json would read with U+FFFD in the place of each bad byte, nor one with a number past the range of a double.
func Text ¶
Text gives the canonical text of a JSON value — 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.
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.