Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

json

v2.2.0
go.gh.ink/json/v2

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

9 matches

Top ↑

Package json delivers encoding/json/v2 semantics behind an import path this module controls.

Every call here forwards to encoding/json/v2 as it stands. The point of the indirection is the seam: when a backend appears that implements v2 semantics faster than the standard library, it slots in behind these functions and callers pick it up by updating the dependency, with no change to their code.

Functions

Marshal

func Marshal(v any, opts ...Options) ([]byte, error)

Marshal encodes v as JSON.

MarshalV1

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

MarshalV1 encodes v as JSON with v1 function signature.

Preheat

func Preheat(vt reflect.Type) error

Preheat compiles the codec for vt ahead of its first use. It is a no-op on backends that have nothing to compile, which today means all of them.

It exists so that callers written against this package keep working when a backend that does precompile arrives.

PreheatMany

func PreheatMany(vts []reflect.Type) error

PreheatMany is the batch form of Preheat.

Unmarshal

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

Unmarshal decodes JSON into v.

UnmarshalV1

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

UnmarshalV1 decodes JSON into v with v1 function signature.

Types

Options

type Options = marshaller.Options

Options configures a call. It is encoding/json/v2's own option type, so every option constructor in encoding/json/v2, encoding/json/jsontext and encoding/json applies here.

Passing encoding/json.DefaultOptionsV1() runs a call with v1 semantics on the v2 engine, which is useful while migrating a caller that still has consumers pinned to v1 output.

Dependency graph