api
v1.15.5
Documentation
pkg.go.dev ↗Constants
OptionUseInt64 (8 declarations)
const ( OptionUseInt64 = consts.OptionUseInt64 OptionUseNumber = consts.OptionUseNumber OptionUseUnicodeErrors = consts.OptionUseUnicodeErrors OptionDisableUnknown = consts.OptionDisableUnknown OptionCopyString = consts.OptionCopyString OptionValidateString = consts.OptionValidateString OptionNoValidateJSON = consts.OptionNoValidateJSON OptionCaseSensitive = consts.OptionCaseSensitive )
Functions
Pretouch
func Pretouch(vt reflect.Type, opts ...option.CompileOption) error
Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in order to reduce the first-hit latency.
Opts are the compile options, for example, "option.WithCompileRecursiveDepth" is a compile option to set the depth of recursive compile for the nested struct type.
PretouchMany
func PretouchMany(vts []reflect.Type, opts ...option.CompileOption) error
PretouchMany compiles all vts ahead-of-time to avoid JIT compilation on-the-fly, in order to reduce the first-hit latency.
Skip
func Skip(data []byte) (start int, end int)
Skip skips only one json value, and returns first non-blank character position and its ending position if it is valid. Otherwise, returns negative error code using start and invalid character position using end
Types
Decoder
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is the decoder context object
NewDecoder
func NewDecoder(s string) *Decoder
NewDecoder creates a new decoder instance.
Decoder.CheckTrailings
func (self *Decoder) CheckTrailings() error
Decoder.CopyString
func (self *Decoder) CopyString()
CopyString indicates the Decoder to decode string values by copying instead of referring.
Decoder.Decode
func (self *Decoder) Decode(val interface{}) error
Decode parses the JSON-encoded data from current position and stores the result in the value pointed to by val.
Decoder.DisallowUnknownFields
func (self *Decoder) DisallowUnknownFields()
DisallowUnknownFields indicates the Decoder to return an error when the destination is a struct and the input contains object keys which do not match any non-ignored, exported fields in the destination.
Decoder.Pos
func (self *Decoder) Pos() int
Pos returns the current decoding position.
Decoder.Reset
func (self *Decoder) Reset(s string)
Decoder.SetOptions
func (self *Decoder) SetOptions(opts Options)
Decoder.UseInt64
func (self *Decoder) UseInt64()
UseInt64 indicates the Decoder to unmarshal an integer into an interface{} as an int64 instead of as a float64.
Decoder.UseNumber
func (self *Decoder) UseNumber()
UseNumber indicates the Decoder to unmarshal a number into an interface{} as a json.Number instead of as a float64.
Decoder.UseUnicodeErrors
func (self *Decoder) UseUnicodeErrors()
UseUnicodeErrors indicates the Decoder to return an error when encounter invalid UTF-8 escape sequences.
Decoder.ValidateString
func (self *Decoder) ValidateString()
ValidateString causes the Decoder to validate string values when decoding string value in JSON. Validation is that, returning error when unescaped control chars(0x00-0x1f) or invalid UTF-8 chars in the string value of JSON.
MismatchTypeError
type MismatchTypeError = errors.MismatchTypeError
Options
type Options = consts.Options
StreamDecoder
type StreamDecoder struct {
Decoder
// contains filtered or unexported fields
}
StreamDecoder is the decoder context object for streaming input.
NewStreamDecoder
func NewStreamDecoder(r io.Reader) *StreamDecoder
NewStreamDecoder adapts to encoding/json.NewDecoder API.
NewStreamDecoder returns a new decoder that reads from r.
StreamDecoder.Buffered
func (self *StreamDecoder) Buffered() io.Reader
Buffered returns a reader of the data remaining in the Decoder's buffer. The reader is valid until the next call to Decode.
StreamDecoder.Decode
func (self *StreamDecoder) Decode(val interface{}) (err error)
Decode decodes input stream into val with corresponding data. Redundantly bytes may be read and left in its buffer, and can be used at next call. Either io error from underlying io.Reader (except io.EOF) or syntax error from data will be recorded and stop subsequently decoding.
StreamDecoder.InputOffset
func (self *StreamDecoder) InputOffset() int64
InputOffset returns the input stream byte offset of the current decoder position. The offset gives the location of the end of the most recently returned token and the beginning of the next token.
StreamDecoder.More
func (self *StreamDecoder) More() bool
More reports whether there is another element in the current array or object being parsed.
SyntaxError
type SyntaxError = errors.SyntaxError