jsoncodec

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 3 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 jsoncodec holds the process-wide JSON codec that the runtime package and runtime/types share.

It is internal because runtime imports types, so types cannot import runtime. The runtime package re-exports its symbols, as aliases of the types and one-line wrappers of the functions, so that nothing is defined twice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

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

Marshal encodes v with the codec.

func MarshalWrite

func MarshalWrite(w io.Writer, v any) error

MarshalWrite encodes v to w: with the codec's MarshalWrite when it implements Streaming, otherwise with Marshal followed by a single Write.

func Set

func Set(c Codec)

Set replaces the codec. nil restores the default, and so does Std itself: it is the default's byte half, and passing it is the natural way to say "encoding/json", not a request for the buffered stream path.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal decodes data into v with the codec.

func UnmarshalRead

func UnmarshalRead(r io.Reader, v any) error

UnmarshalRead decodes v from r: with the codec's UnmarshalRead when it implements Streaming, otherwise by reading r to its end and calling Unmarshal. When r is nil or holds no value, nothing or only JSON white space, it returns io.EOF without involving the codec, whose own report of an empty input varies.

Types

type Codec

type Codec interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(data []byte, v any) error
}

Codec encodes and decodes JSON. runtime.JSONCodec is an alias of it.

type Std

type Std struct{}

Std is encoding/json's json.Marshal and json.Unmarshal. runtime.StdJSONCodec is an alias of it.

It deliberately doesn't implement Streaming: a codec that embeds it and overrides Marshal or Unmarshal then encodes and decodes streams through its own methods, via MarshalWrite and UnmarshalRead's fall-through, rather than through encoding/json's Encoder and Decoder promoted from Std.

func (Std) Marshal

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

func (Std) Unmarshal

func (Std) Unmarshal(data []byte, v any) error

type Streaming

type Streaming interface {
	MarshalWrite(w io.Writer, v any) error
	UnmarshalRead(r io.Reader, v any) error
}

Streaming is optionally implemented by a Codec that encodes to and decodes from a stream. runtime.StreamingJSONCodec is an alias of it.

Jump to

Keyboard shortcuts

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