json

package
v0.0.0-...-67c52db Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnexpectedEOF = errors.New("%v", io.ErrUnexpectedEOF)

ErrUnexpectedEOF means that EOF was encountered in the middle of the input.

Functions

func NewDecoder

func NewDecoder(b []byte) codec.Decoder

NewDecoder returns a Decoder to read the given []byte.

func NewEncoder

func NewEncoder(indent string) (codec.Encoder, error)

NewEncoder returns an Encoder.

If indent is a non-empty string, it causes every entry for an Array or Object to be preceded by the indent and trailed by a newline.

Types

type Decoder

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

Decoder is a token-based JSON decoder.

func (*Decoder) Clone

func (d *Decoder) Clone() codec.Decoder

Clone returns a copy of the Decoder for use in reading ahead the next JSON object, array or other values without affecting current Decoder.

func (*Decoder) Peek

func (d *Decoder) Peek() (codec.Token, error)

Peek looks ahead and returns the next token kind without advancing a read.

func (*Decoder) Position

func (d *Decoder) Position(idx int) (line int, column int)

Position returns line and column number of given index of the original input. It will panic if index is out of range.

func (*Decoder) Read

func (d *Decoder) Read() (codec.Token, error)

Read returns the next JSON token. It will return an error if there is no valid token.

type Encoder

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

Encoder provides methods to write out JSON constructs and values. The user is responsible for producing valid sequences of JSON constructs and values.

func (*Encoder) Bytes

func (e *Encoder) Bytes() []byte

Bytes returns the content of the written bytes.

func (*Encoder) EndArray

func (e *Encoder) EndArray()

EndArray writes out the ']' symbol.

func (*Encoder) EndObject

func (e *Encoder) EndObject()

EndObject writes out the '}' symbol.

func (*Encoder) StartArray

func (e *Encoder) StartArray()

StartArray writes out the '[' symbol.

func (*Encoder) StartObject

func (e *Encoder) StartObject()

StartObject writes out the '{' symbol.

func (*Encoder) WriteBool

func (e *Encoder) WriteBool(b bool)

WriteBool writes out the given boolean value.

func (*Encoder) WriteFloat

func (e *Encoder) WriteFloat(n float64, bitSize int)

WriteFloat writes out the given float and bitSize in JSON number value.

func (*Encoder) WriteInt

func (e *Encoder) WriteInt(n int64)

WriteInt writes out the given signed integer in JSON number value.

func (*Encoder) WriteName

func (e *Encoder) WriteName(s string) error

WriteName writes out the given string in JSON string value and the name separator ':'. Returns error if input string contains invalid UTF-8, which should not be likely as protobuf field names should be valid.

func (*Encoder) WriteNull

func (e *Encoder) WriteNull()

WriteNull writes out the null value.

func (*Encoder) WriteString

func (e *Encoder) WriteString(s string) error

WriteString writes out the given string in JSON string value. Returns error if input string contains invalid UTF-8.

func (*Encoder) WriteUint

func (e *Encoder) WriteUint(n uint64)

WriteUint writes out the given unsigned integer in JSON number value.

Jump to

Keyboard shortcuts

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