json

package
v0.13.10 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

README

json

Package json provides configurable interfaces for JSON encoding and decoding.

Documentation

Overview

Package json provides configurable interfaces for JSON encoding and decoding.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Marshal marshals the given value into a JSON string.
	Marshal = json.Marshal

	// Unmarshal unmarshals the given JSON string into v.
	Unmarshal = json.Unmarshal

	// MarshalIndent marshals the given value into a JSON string with indentation.
	MarshalIndent = json.MarshalIndent

	// Indent is the indentation used in MarshalIndent.
	Indent = json.Indent

	// NewEncoder returns a new JSON encoder that writes to w.
	NewEncoder = json.NewEncoder

	// NewDecoder returns a new JSON decoder that reads from r.
	NewDecoder = json.NewDecoder
)
View Source
var (
	// EmptyStringBytes is a byte slice containing an empty JSON string.
	EmptyStringBytes = []byte(`""`)

	// NullBytes is a byte slice containing the JSON null literal.
	NullBytes = []byte("null")
)

Functions

func NewPtr

func NewPtr[T any](t T) *T

NewPtr returns a pointer of t.

Types

type Marshaler

type Marshaler = json.Marshaler

Marshaler is the interface implemented by types that can marshal JSON.

type Nullable

type Nullable[T any] struct {
	// contains filtered or unexported fields
}

Nullable represents a nullable value. It gets serialized as either null or the value.

func New

func New[T any](t T) Nullable[T]

New returns a new Nullable with t as the value.

func NewOptional

func NewOptional[T any](t T) *Nullable[T]

NewOptional returns a pointer to a new Nullable with t as the value.

func Null

func Null[T any]() Nullable[T]

Null returns a null Nullable.

func OptionalNull

func OptionalNull[T any]() *Nullable[T]

OptionalNull returns a pointer to a null Nullable.

func (Nullable[T]) IsNull

func (n Nullable[T]) IsNull() bool

IsNull returns true if the Nullable is null.

func (Nullable[T]) MarshalJSON

func (n Nullable[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaler interface.

func (*Nullable[T]) UnmarshalJSON

func (n *Nullable[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaler interface.

func (Nullable[T]) Value

func (n Nullable[T]) Value() T

Value returns the value of the Nullable. If the Nullable is null, it returns the zero value of T.

type RawMessage

type RawMessage = json.RawMessage

RawMessage is a raw encoded JSON value.

type Unmarshaler

type Unmarshaler = json.Unmarshaler

Unmarshaler is the interface implemented by types that can unmarshal a JSON description of themselves.

Jump to

Keyboard shortcuts

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