json

package
v0.26.21 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package json wraps encoding/json as a codec.Codec implementation registered under Format("json"). Blank-importing this package is enough to make JSON resolvable via the core/data/codec registry.

It also re-exports the JSON appenders of internal/kernel/jsonenc — AppendString, AppendEscaped, AppendInt, AppendUint, BeginObject and the Object it returns — for the programs that write a JSON document by hand and want the escaping the SDK's own emitters use (ADR 0186 §D10). They register no codec and read no value by reflection; Marshal is still encoding/json, and does not change. A string is escaped as encoding/json escapes it, except that '<', '>' and '&' are NOT.

Package json — adapts *encoding/json.Decoder to codec.Decoder.

Package json — adapts *encoding/json.Encoder to codec.Encoder.

Index

Constants

This section is empty.

Variables

View Source
var Codec codec.Codec = codec.Register(&jsonCodec{})

Codec is the JSON singleton, registered with core/data/codec at package load. Binding the registration result to a named var is more idiomatic than `var _ = codec.Register(...)` and keeps us clear of init().

Functions

func AppendEscaped added in v0.26.15

func AppendEscaped(dst []byte, s string) []byte

AppendEscaped appends the body of the JSON string literal of s — what AppendString writes between its quotes — so a caller can join several pieces into one literal.

func AppendInt added in v0.26.15

func AppendInt(dst []byte, v int64) []byte

AppendInt appends v to dst in decimal, as a JSON number.

func AppendString added in v0.26.15

func AppendString(dst []byte, s string) []byte

AppendString appends s to dst as a JSON string literal, quotes included. See the package comment for the escapes: invalid UTF-8 becomes U+FFFD, U+2028 and U+2029 are escaped, and '<', '>' and '&' are not.

func AppendUint added in v0.26.15

func AppendUint(dst []byte, v uint64) []byte

AppendUint appends v to dst in decimal, as a JSON number. A value past 2^53 is exact here and is not in a JavaScript reader.

func New

func New() codec.Codec

New returns the JSON codec singleton.

Types

type Object added in v0.26.15

type Object = jsonenc.Object

Object is a JSON object being written by BeginObject: members land in the order they are named, and nothing allocates but the caller's slice.

func BeginObject added in v0.26.15

func BeginObject(dst []byte) Object

BeginObject appends the opening brace of an object to dst and returns the Object that writes its members after it, in the order they are named.

Jump to

Keyboard shortcuts

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