Documentation ¶
Overview ¶
Package jsoniter implements encoding and decoding of JSON as defined in RFC 4627 and provides interfaces with identical syntax of standard lib encoding/json. Converting from encoding/json to jsoniter is no more than replacing the package with jsoniter and variable type declarations (if any). jsoniter interfaces gives 100% compatibility with code using standard lib.
"JSON and Go" (https://golang.org/doc/articles/json_and_go.html) gives a description of how Marshal/Unmarshal operate between arbitrary or predefined json objects and bytes, and it applies to jsoniter.Marshal/Unmarshal as well.
Besides, jsoniter.Iterator provides a different set of interfaces iterating given bytes/string/reader and yielding parsed elements one by one. This set of interfaces reads input as required and gives better performance.
Index ¶
- type Iterator
- func (iter *Iterator) CurrentBuffer() string
- func (iter *Iterator) ReadArray() (ret bool)
- func (iter *Iterator) ReadArrayCB(callback func(*Iterator) bool) (ret bool)
- func (iter *Iterator) ReadBigFloat() (ret *big.Float)
- func (iter *Iterator) ReadBigInt() (ret *big.Int)
- func (iter *Iterator) ReadBool() (ret bool)
- func (iter *Iterator) ReadFloat32() (ret float32)
- func (iter *Iterator) ReadFloat64() (ret float64)
- func (iter *Iterator) ReadInt() int
- func (iter *Iterator) ReadInt16() (ret int16)
- func (iter *Iterator) ReadInt32() (ret int32)
- func (iter *Iterator) ReadInt64() (ret int64)
- func (iter *Iterator) ReadInt8() (ret int8)
- func (iter *Iterator) ReadMapCB(callback func(*Iterator, string) bool) bool
- func (iter *Iterator) ReadNil() (ret bool)
- func (iter *Iterator) ReadNumber() (ret json.Number)
- func (iter *Iterator) ReadObject() (ret string)
- func (iter *Iterator) ReadObjectCB(callback func(*Iterator, string) bool) bool
- func (iter *Iterator) ReadString() (ret string)
- func (iter *Iterator) ReadStringAsSlice() (ret []byte)
- func (iter *Iterator) ReadUint() uint
- func (iter *Iterator) ReadUint16() (ret uint16)
- func (iter *Iterator) ReadUint32() (ret uint32)
- func (iter *Iterator) ReadUint64() uint64
- func (iter *Iterator) ReadUint8() (ret uint8)
- func (iter *Iterator) ReportError(operation string, msg string)
- func (iter *Iterator) Reset(reader io.Reader) *Iterator
- func (iter *Iterator) ResetBytes(input []byte) *Iterator
- func (iter *Iterator) Skip()
- func (iter *Iterator) SkipAndAppendBytes(buf []byte) []byte
- func (iter *Iterator) SkipAndReturnBytes() []byte
- func (iter *Iterator) WhatIsNext() ValueType
- type Stream
- func (stream *Stream) Available() int
- func (stream *Stream) Buffer() []byte
- func (stream *Stream) Buffered() int
- func (stream *Stream) Flush() error
- func (stream *Stream) Reset(out io.Writer)
- func (stream *Stream) SetBuffer(buf []byte)
- func (stream *Stream) Write(p []byte) (nn int, err error)
- func (stream *Stream) WriteArrayEnd()
- func (stream *Stream) WriteArrayStart()
- func (stream *Stream) WriteBool(val bool)
- func (stream *Stream) WriteEmptyArray()
- func (stream *Stream) WriteEmptyObject()
- func (stream *Stream) WriteFalse()
- func (stream *Stream) WriteFloat32(val float32)
- func (stream *Stream) WriteFloat32Lossy(val float32)
- func (stream *Stream) WriteFloat64(val float64)
- func (stream *Stream) WriteFloat64Lossy(val float64)
- func (stream *Stream) WriteInt(val int)
- func (stream *Stream) WriteInt16(nval int16)
- func (stream *Stream) WriteInt32(nval int32)
- func (stream *Stream) WriteInt64(nval int64)
- func (stream *Stream) WriteInt8(nval int8)
- func (stream *Stream) WriteMore()
- func (stream *Stream) WriteNil()
- func (stream *Stream) WriteObjectEnd()
- func (stream *Stream) WriteObjectField(field string)
- func (stream *Stream) WriteObjectStart()
- func (stream *Stream) WriteRaw(s string)
- func (stream *Stream) WriteString(s string)
- func (stream *Stream) WriteStringWithHTMLEscaped(s string)
- func (stream *Stream) WriteTrue()
- func (stream *Stream) WriteUint(val uint)
- func (stream *Stream) WriteUint16(val uint16)
- func (stream *Stream) WriteUint32(val uint32)
- func (stream *Stream) WriteUint64(val uint64)
- func (stream *Stream) WriteUint8(val uint8)
- type ValueType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
type Iterator struct { Error error Attachment interface{} // open for customized decoder // contains filtered or unexported fields }
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.
func ParseBytes ¶
ParseBytes creates an Iterator instance from byte array
func ParseString ¶
ParseString creates an Iterator instance from string
func (*Iterator) CurrentBuffer ¶
CurrentBuffer gets current buffer as string for debugging purpose
func (*Iterator) ReadArray ¶
ReadArray read array element, tells if the array has more element to read.
func (*Iterator) ReadArrayCB ¶
ReadArrayCB read array with callback
func (*Iterator) ReadBigFloat ¶
ReadBigFloat read big.Float
func (*Iterator) ReadBigInt ¶
ReadBigInt read big.Int
func (*Iterator) ReadFloat32 ¶
ReadFloat32 read float32
func (*Iterator) ReadFloat64 ¶
ReadFloat64 read float64
func (*Iterator) ReadNumber ¶
ReadNumber read json.Number
func (*Iterator) ReadObject ¶
ReadObject read one field from object. If object ended, returns empty string. Otherwise, returns the field name.
func (*Iterator) ReadObjectCB ¶
ReadObjectCB read object with callback, the key is ascii only and field name not copied
func (*Iterator) ReadString ¶
ReadString read string from iterator
func (*Iterator) ReadStringAsSlice ¶
ReadStringAsSlice read string from iterator without copying into string form. The []byte can not be kept, as it will change after next iterator call.
func (*Iterator) ReadUint16 ¶
ReadUint16 read uint16
func (*Iterator) ReadUint32 ¶
ReadUint32 read uint32
func (*Iterator) ReportError ¶
ReportError record a error in iterator instance with current position.
func (*Iterator) ResetBytes ¶
ResetBytes reuse iterator instance by specifying another byte array as input
func (*Iterator) Skip ¶
func (iter *Iterator) Skip()
Skip skips a json object and positions to relatively the next json object
func (*Iterator) SkipAndAppendBytes ¶
SkipAndAppendBytes skips next JSON element and appends its content to buffer, returning the result.
func (*Iterator) SkipAndReturnBytes ¶
SkipAndReturnBytes skip next JSON element, and return its content as []byte. The []byte can be kept, it is a copy of data.
func (*Iterator) WhatIsNext ¶
WhatIsNext gets ValueType of relatively next json element
type Stream ¶
type Stream struct { Error error Attachment interface{} // open for customized encoder // contains filtered or unexported fields }
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.
func NewStream ¶
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.
func (*Stream) Buffered ¶
Buffered returns the number of bytes that have been written into the current buffer.
func (*Stream) Write ¶
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.
func (*Stream) WriteArrayEnd ¶
func (stream *Stream) WriteArrayEnd()
WriteArrayEnd write ] with possible indention
func (*Stream) WriteArrayStart ¶
func (stream *Stream) WriteArrayStart()
WriteArrayStart write [ with possible indention
func (*Stream) WriteEmptyObject ¶
func (stream *Stream) WriteEmptyObject()
WriteEmptyObject write {}
func (*Stream) WriteFloat32 ¶
WriteFloat32 write float32 to stream
func (*Stream) WriteFloat32Lossy ¶
WriteFloat32Lossy write float32 to stream with ONLY 6 digits precision although much much faster
func (*Stream) WriteFloat64 ¶
WriteFloat64 write float64 to stream
func (*Stream) WriteFloat64Lossy ¶
WriteFloat64Lossy write float64 to stream with ONLY 6 digits precision although much much faster
func (*Stream) WriteInt16 ¶
WriteInt16 write int16 to stream
func (*Stream) WriteInt32 ¶
WriteInt32 write int32 to stream
func (*Stream) WriteInt64 ¶
WriteInt64 write int64 to stream
func (*Stream) WriteMore ¶
func (stream *Stream) WriteMore()
WriteMore write , with possible indention
func (*Stream) WriteObjectEnd ¶
func (stream *Stream) WriteObjectEnd()
WriteObjectEnd write } with possible indention
func (*Stream) WriteObjectField ¶
WriteObjectField write "field": with possible indention
func (*Stream) WriteObjectStart ¶
func (stream *Stream) WriteObjectStart()
WriteObjectStart write { with possible indention
func (*Stream) WriteString ¶
WriteString write string to stream without html escape
func (*Stream) WriteStringWithHTMLEscaped ¶
WriteStringWithHTMLEscaped write string to stream with html special characters escaped
func (*Stream) WriteUint16 ¶
WriteUint16 write uint16 to stream
func (*Stream) WriteUint32 ¶
WriteUint32 write uint32 to stream
func (*Stream) WriteUint64 ¶
WriteUint64 write uint64 to stream
func (*Stream) WriteUint8 ¶
WriteUint8 write uint8 to stream
type ValueType ¶
type ValueType int
ValueType the type for JSON element
const ( // InvalidValue invalid JSON element InvalidValue ValueType = iota // StringValue JSON element "string" StringValue // NumberValue JSON element 100 or 0.10 NumberValue // NilValue JSON element null NilValue // BoolValue JSON element true or false BoolValue // ArrayValue JSON element [] ArrayValue // ObjectValue JSON element {} ObjectValue )