json

package
v0.2.16 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package json provides an interface to functions and types in the standard encoding/json package to facilitate mocking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal added in v0.2.15

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

Marshal returns the JSON encoding of v by calling encoding/json.Marshal.

func MarshalIndent added in v0.2.15

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

MarshalIndent returns formatted JSON encoding of v by calling encoding/json.MarshalIndent.

func Unmarshal added in v0.2.15

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

Unmarshal parses the JSON-encoded data and stores the result by calling encoding/json.Unmarshal.

Types

type Decoder

type Decoder interface {
	Decode(v any) error
	Buffered() io.Reader
	InputOffset() int64
	More() bool
	Token() (Token, error)
	Nub() *json.Decoder
}

func NewDecoder added in v0.2.15

func NewDecoder(r io.Reader, options ...DecoderOption) Decoder

NewDecoder creates a new Decoder that reads from r with optional configuration.

func WrapDecoder

func WrapDecoder(dec *json.Decoder) Decoder

type DecoderOption

type DecoderOption func(*json.Decoder)

func WithDisallowUnknownFields

func WithDisallowUnknownFields() DecoderOption

func WithUseNumber

func WithUseNumber() DecoderOption

type Delim

type Delim = json.Delim

Value types

type Encoder

type Encoder interface {
	Encode(v any) error
	SetIndent(prefix, indent string)
	SetEscapeHTML(on bool)
	Nub() *json.Encoder
}

func NewEncoder added in v0.2.15

func NewEncoder(w io.Writer, options ...EncoderOption) Encoder

NewEncoder creates a new Encoder that writes to w with optional configuration.

func WrapEncoder

func WrapEncoder(enc *json.Encoder) Encoder

type EncoderOption

type EncoderOption func(*json.Encoder)

func WithEscapeHTML

func WithEscapeHTML(on bool) EncoderOption

func WithIndent

func WithIndent(prefix, indent string) EncoderOption

type InvalidUnmarshalError

type InvalidUnmarshalError = json.InvalidUnmarshalError

Error types

type JSON

type JSON interface {
	// Functions:
	Marshal(v any) ([]byte, error)
	MarshalIndent(v any, prefix, indent string) ([]byte, error)
	Unmarshal(data []byte, v any) error
	Compact(dst *bytes.Buffer, src []byte) error
	HTMLEscape(dst *bytes.Buffer, src []byte)
	Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error
	Valid(data []byte) bool

	// Constructors:
	NewDecoder(r io.Reader, options ...DecoderOption) Decoder
	NewEncoder(w io.Writer, options ...EncoderOption) Encoder
}

func NewJSON

func NewJSON() JSON

type Marshaler

type Marshaler = json.Marshaler

Interfaces for custom marshaling/unmarshaling

type MarshalerError

type MarshalerError = json.MarshalerError

type Number

type Number = json.Number

type RawMessage

type RawMessage = json.RawMessage

type SyntaxError

type SyntaxError = json.SyntaxError

type Token

type Token = json.Token

type UnmarshalTypeError

type UnmarshalTypeError = json.UnmarshalTypeError

type Unmarshaler

type Unmarshaler = json.Unmarshaler

type UnsupportedTypeError

type UnsupportedTypeError = json.UnsupportedTypeError

type UnsupportedValueError

type UnsupportedValueError = json.UnsupportedValueError

Jump to

Keyboard shortcuts

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