json

package
v1.18.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 License: MIT Imports: 5 Imported by: 77

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 interface{}) ([]byte, error)

Marshal converts object as bytes

func MarshalIndent

func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)

MarshalIndent copied from encoding/json

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal decodes object from bytes

func UnmarshalHandleDoubleEncode

func UnmarshalHandleDoubleEncode(bs []byte, v interface{}) 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 interface{}) error
}

Decoder represents a decoder for json

func NewDecoder

func NewDecoder(reader io.Reader) Decoder

NewDecoder creates a decoder to read objects from reader

type Encoder

type Encoder interface {
	Encode(v interface{}) 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 interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) 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

var (
	// DefaultJSONHandler default json handler
	DefaultJSONHandler Interface = JSONiter{jsoniter.ConfigCompatibleWithStandardLibrary}
)

type JSONiter

type JSONiter struct {
	jsoniter.API
}

JSONiter implements Interface via jsoniter

func (JSONiter) Indent

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

Indent implements Interface, since jsoniter don't support Indent, just use encoding/json's

func (JSONiter) Marshal

func (j JSONiter) Marshal(v interface{}) ([]byte, error)

Marshal implements Interface

func (JSONiter) NewDecoder

func (j JSONiter) NewDecoder(reader io.Reader) Decoder

NewDecoder implements Interface

func (JSONiter) NewEncoder

func (j JSONiter) NewEncoder(writer io.Writer) Encoder

NewEncoder implements Interface

func (JSONiter) Unmarshal

func (j JSONiter) Unmarshal(data []byte, v interface{}) error

Unmarshal implements Interface

type StdJSON

type StdJSON struct{}

StdJSON implements Interface via encoding/json

func (StdJSON) Indent

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

Indent implements Interface

func (StdJSON) Marshal

func (StdJSON) Marshal(v interface{}) ([]byte, error)

Marshal implements Interface

func (StdJSON) NewDecoder

func (StdJSON) NewDecoder(reader io.Reader) Decoder

NewDecoder implements Interface

func (StdJSON) NewEncoder

func (StdJSON) NewEncoder(writer io.Writer) Encoder

NewEncoder implements Interface

func (StdJSON) Unmarshal

func (StdJSON) Unmarshal(data []byte, v interface{}) error

Unmarshal implements Interface

Jump to

Keyboard shortcuts

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