Decoder reads and decodes JSON values from an input stream.
Decoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress) Buffered remaining buffer Decode decode JSON into interface{} DisallowUnknownFields causes 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. More is there more? UseNumber causes the Decoder to unmarshal a number into an interface{} as a
Number instead of as a float64.
*Decoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Decoder
func NewDecoder(reader io.Reader) *Decoder
func API.NewDecoder(reader io.Reader) *Decoder
CreateDecoder get decoder from map CreateEncoder No-op CreateMapKeyDecoder No-op CreateMapKeyEncoder No-op DecorateDecoder No-op DecorateEncoder No-op UpdateStructDescriptor No-op
DecoderExtension : Extension
DummyExtension embed this type get dummy implementation for all methods of Extension CreateDecoder No-op CreateEncoder No-op CreateMapKeyDecoder No-op CreateMapKeyEncoder No-op DecorateDecoder No-op DecorateEncoder No-op UpdateStructDescriptor No-op
*DummyExtension : Extension
Encoder same as json.Encoder Encode encode interface{} as JSON to io.Writer SetEscapeHTML escape html by default, set to false to disable SetIndent set the indention. Prefix is not supported
*Encoder : github.com/grpc-ecosystem/grpc-gateway/v2/runtime.Encoder
*Encoder : go.uber.org/zap/zapcore.ReflectedEncoder
func NewEncoder(writer io.Writer) *Encoder
func API.NewEncoder(writer io.Writer) *Encoder
CreateDecoder No-op CreateEncoder get encoder from map CreateMapKeyDecoder No-op CreateMapKeyEncoder No-op DecorateDecoder No-op DecorateEncoder No-op UpdateStructDescriptor No-op
EncoderExtension : Extension
Iterator is a io.Reader like object, with JSON specific read functions.
Error is not returned as return value, but stored as Error member on this iterator instance. // open for customized decoderErrorerror CurrentBuffer gets current buffer as string for debugging purpose Pool returns a pool can provide more iterator with same configuration Read read the next JSON element as generic interface{}. ReadAny read next JSON element as an Any object. It is a better json.RawMessage. ReadArray read array element, tells if the array has more element to read. ReadArrayCB read array with callback ReadBigFloat read big.Float ReadBigInt read big.Int ReadBool reads a json object as BoolValue ReadFloat32 read float32 ReadFloat64 read float64 ReadInt read int ReadInt16 read int16 ReadInt32 read int32 ReadInt64 read int64 ReadInt8 read int8 ReadMapCB read map with callback, the key can be any string ReadNil reads a json object as nil and
returns whether it's a nil or not ReadNumber read json.Number ReadObject read one field from object.
If object ended, returns empty string.
Otherwise, returns the field name. ReadObjectCB read object with callback, the key is ascii only and field name not copied ReadString read string from iterator ReadStringAsSlice read string from iterator without copying into string form.
The []byte can not be kept, as it will change after next iterator call. ReadUint read uint ReadUint16 read uint16 ReadUint32 read uint32 ReadUint64 read uint64 ReadUint8 read uint8 ReadVal copy the underlying JSON into go interface, same as json.Unmarshal ReportError record a error in iterator instance with current position. Reset reuse iterator instance by specifying another reader ResetBytes reuse iterator instance by specifying another byte array as input Skip skips a json object and positions to relatively the next json object SkipAndAppendBytes skips next JSON element and appends its content to
buffer, returning the result. SkipAndReturnBytes skip next JSON element, and return its content as []byte.
The []byte can be kept, it is a copy of data. WhatIsNext gets ValueType of relatively next json element
func NewIterator(cfg API) *Iterator
func Parse(cfg API, reader io.Reader, bufSize int) *Iterator
func ParseBytes(cfg API, input []byte) *Iterator
func ParseString(cfg API, input string) *Iterator
func API.BorrowIterator(data []byte) *Iterator
func (*Iterator).Reset(reader io.Reader) *Iterator
func (*Iterator).ResetBytes(input []byte) *Iterator
func IteratorPool.BorrowIterator(data []byte) *Iterator
func API.ReturnIterator(iter *Iterator)
func IteratorPool.ReturnIterator(iter *Iterator)
func (*OptionalDecoder).Decode(ptr unsafe.Pointer, iter *Iterator)
func ValDecoder.Decode(ptr unsafe.Pointer, iter *Iterator)
Float64 returns the number as a float64. Int64 returns the number as an int64. String returns the literal text of the number.
Number : expvar.Var
Number : fmt.Stringer
stream is a io.Writer like object, with JSON specific write functions.
Error is not returned as return value, but stored as Error member on this stream instance. // open for customized encoderErrorerror Available returns how many bytes are unused in the buffer. Buffer if writer is nil, use this method to take the result Buffered returns the number of bytes that have been written into the current buffer. Flush writes any buffered data to the underlying io.Writer. Pool returns a pool can provide more stream with same configuration Reset reuse this stream instance by assign a new writer SetBuffer allows to append to the internal buffer directly Write writes the contents of p into the buffer.
It returns the number of bytes written.
If nn < len(p), it also returns an error explaining
why the write is short. WriteArrayEnd write ] with possible indention WriteArrayStart write [ with possible indention WriteBool write true or false into stream WriteEmptyArray write [] WriteEmptyObject write {} WriteFalse write false to stream WriteFloat32 write float32 to stream WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster WriteFloat64 write float64 to stream WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster WriteInt write int to stream WriteInt16 write int16 to stream WriteInt32 write int32 to stream WriteInt64 write int64 to stream WriteInt8 write int8 to stream WriteMore write , with possible indention WriteNil write null to stream WriteObjectEnd write } with possible indention WriteObjectField write "field": with possible indention WriteObjectStart write { with possible indention WriteRaw write string out without quotes, just like []byte WriteString write string to stream without html escape WriteStringWithHTMLEscaped write string to stream with html special characters escaped WriteTrue write true to stream WriteUint write uint to stream WriteUint16 write uint16 to stream WriteUint32 write uint32 to stream WriteUint64 write uint64 to stream WriteUint8 write uint8 to stream WriteVal copy the go interface into underlying JSON, same as json.Marshal
*Stream : github.com/apache/thrift/lib/go/thrift.Flusher
*Stream : github.com/miekg/dns.Writer
*Stream : internal/bisect.Writer
*Stream : io.Writer
func NewStream(cfg API, out io.Writer, bufSize int) *Stream
func API.BorrowStream(writer io.Writer) *Stream
func StreamPool.BorrowStream(writer io.Writer) *Stream
func Any.WriteTo(stream *Stream)
func API.ReturnStream(stream *Stream)
func (*OptionalEncoder).Encode(ptr unsafe.Pointer, stream *Stream)
func StreamPool.ReturnStream(stream *Stream)
func ValEncoder.Encode(ptr unsafe.Pointer, stream *Stream)
Get quick method to get value from deeply nested JSON structure
Marshal adapts to json/encoding Marshal API
Marshal returns the JSON encoding of v, adapts to json/encoding Marshal API
Refer to https://godoc.org/encoding/json#Marshal for more information
MarshalIndent same as json.MarshalIndent. Prefix is not supported.
MarshalToString convenient method to write as string instead of []byte
NewDecoder adapts to json/stream NewDecoder API.
NewDecoder returns a new decoder that reads from r.
Instead of a json/encoding Decoder, an Decoder is returned
Refer to https://godoc.org/encoding/json#NewDecoder for more information
NewEncoder same as json.NewEncoder
NewIterator creates an empty Iterator instance
NewStream create new stream instance.
cfg can be jsoniter.ConfigDefault.
out can be nil if write to internal buffer.
bufSize is the initial size for the internal buffer in bytes.
Parse creates an Iterator instance from io.Reader
ParseBytes creates an Iterator instance from byte array
ParseString creates an Iterator instance from string
RegisterExtension register extension
RegisterFieldDecoder register TypeDecoder for a struct field
RegisterFieldDecoderFunc register TypeDecoder for a struct field with function
RegisterFieldEncoder register TypeEncoder for a struct field
RegisterFieldEncoderFunc register TypeEncoder for a struct field with encode/isEmpty function
RegisterTypeDecoder register TypeDecoder for a typ
RegisterTypeDecoderFunc register TypeDecoder for a type with function
RegisterTypeEncoder register TypeEncoder for a type
RegisterTypeEncoderFunc register TypeEncoder for a type with encode/isEmpty function
Unmarshal adapts to json/encoding Unmarshal API
Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v.
Refer to https://godoc.org/encoding/json#Unmarshal for more information
UnmarshalFromString is a convenient method to read from string instead of []byte
Valid reports whether data is a valid JSON encoding.
Wrap turn a go object into Any interface
WrapFloat64 turn float64 into Any interface
WrapInt32 turn int32 into Any interface
WrapInt64 turn int64 into Any interface
WrapString turn string into Any interface
WrapUint32 turn uint32 into Any interface
WrapUint64 turn uint64 into Any interface
Package-Level Variables (total 3)
ConfigCompatibleWithStandardLibrary tries to be 100% compatible with standard library behavior
ConfigDefault the default API
ConfigFastest marshals float with only 6 digits precision
Package-Level Constants (total 7)
ArrayValue JSON element []
BoolValue JSON element true or false
InvalidValue invalid JSON element
NilValue JSON element null
NumberValue JSON element 100 or 0.10
ObjectValue JSON element {}
StringValue JSON element "string"
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.