canonical

package
v0.3.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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). Parse reads a JSON text into such a tree, an integer as an int64, for the readers of a package and of the module index (R35). 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

View Source
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

func Digest(data []byte) formatv0.Digest

Digest gives the digest of bytes: sha256: and their SHA-256 in 64 lowercase hexadecimal digits (format/README.md, section 25).

func Parse added in v0.1.22

func Parse(data []byte) (any, error)

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 (RFC 8259, section 8.1), nor one with a number past the range of a double. Package modulepackage reads the texts of a package by it, and package moduleindex the module index (R34, R35).

func Text

func Text(value any) ([]byte, error)

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.

Types

type Error

type Error struct {
	Pointer string
	Message string
}

An Error is a value that the canonical text cannot hold, at its place in the value as a JSON Pointer in URI fragment form, such as #/tasks/sum/items/0. Of a module that passed its check, it is a fault of module-kit, not of the author (R09).

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL