Help us shape the future of Go! Take the 2026 Go Developer Survey

json

package
v1.27.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultJSONHandler = getDefaultJSONHandler()

Functions

func Indent

func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error

Indent appends to dst an indented form of the JSON-encoded src.

func Marshal

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

Marshal converts object as bytes

func MarshalIndent

func MarshalIndent(v any, prefix, indent string) ([]byte, error)

MarshalIndent copied from encoding/json

func MarshalKeepOptionalEmpty

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

func Unmarshal

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

Unmarshal decodes object from bytes

func UnmarshalHandleDoubleEncode

func UnmarshalHandleDoubleEncode(bs []byte, v any) error

UnmarshalHandleDoubleEncode - due to a bug in xorm (see https://gitea.com/xorm/xorm/pulls/1957) - it's possible that a Blob may be double encoded or gain an unwanted prefix of 0xff 0xfe.

func Valid

func Valid(data []byte) bool

Valid proxy to json.Valid

Types

type Decoder

type Decoder interface {
	Decode(v any) error
}

Decoder represents a decoder for json

func NewDecoder

func NewDecoder(reader io.Reader) Decoder

NewDecoder creates a decoder to read objects from reader

func NewDecoderCaseInsensitive

func NewDecoderCaseInsensitive(reader io.Reader) Decoder

type Encoder

type Encoder interface {
	Encode(v any) error
}

Encoder represents an encoder for json

func NewEncoder

func NewEncoder(writer io.Writer) Encoder

NewEncoder creates an encoder to write objects to writer

type Interface

type Interface interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(data []byte, v any) error
	NewEncoder(writer io.Writer) Encoder
	NewDecoder(reader io.Reader) Decoder
	Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error
}

Interface represents an interface to handle json data

type JSONv2

type JSONv2 struct {
	// contains filtered or unexported fields
}

JSONv2 implements Interface via encoding/json/v2 Requires GOEXPERIMENT=jsonv2 to be set at build time

func (*JSONv2) Indent

func (*JSONv2) Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error

Indent implements Interface using standard library (JSON v2 doesn't have Indent yet)

func (*JSONv2) Marshal

func (j *JSONv2) Marshal(v any) ([]byte, error)

func (*JSONv2) NewDecoder

func (j *JSONv2) NewDecoder(reader io.Reader) Decoder

func (*JSONv2) NewEncoder

func (j *JSONv2) NewEncoder(writer io.Writer) Encoder

func (*JSONv2) Unmarshal

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

type Value

type Value = jsontext.Value

Jump to

Keyboard shortcuts

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