jcs

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package jcs writes the JSON Canonicalization Scheme of RFC 8785: one byte form for a JSON document, whatever the order of its members or the spelling of its numbers and strings, so it can be signed or hashed and checked by anyone who canonicalizes the same document.

The canonical form

The document must be one I-JSON value (RFC 7493): valid UTF-8, no duplicated member name, no trailing data. It is then written with no whitespace; object members sorted by their names' UTF-16 code units (§3.2.3), recursively; strings with only '"', '\\' and the control characters escaped — \b, \t, \n, \f and \r by name, the others as \u00XX in lower case — and every other character as itself (§3.2.2.2); numbers as ECMAScript writes an IEEE 754 double (§3.2.2.3): the shortest digits that read back as the same double, in decimal notation from 1e-6 up to 1e21 and in exponent notation outside, -0 as 0. A number past the largest finite double is refused.

It is not a codec Format (ADR 0102's precedent): a canonical form is a policy over JSON, not a wire format of its own. Nothing it returns in an error comes from the document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonicalize

func Canonicalize(doc []byte) ([]byte, error)

Canonicalize returns the RFC 8785 canonical form of the JSON document doc. It returns NotJSON — naming the offset, never a byte of the document — when doc is not exactly one I-JSON value, and NumberInvalid for a number past the largest finite double.

func Marshal

func Marshal(v any) ([]byte, error)

Marshal returns the canonical form of v: its encoding/json/v2 encoding — the default options, which refuse invalid UTF-8 as I-JSON does — then Canonicalize. A value json/v2 refuses is MarshalFailed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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