Documentation ¶
Index ¶
- Constants
- Variables
- func CastJsonNumber(val interface{}) (string, bool)
- func Marshal(v interface{}) ([]byte, error)
- func MarshalContext(ctx context.Context, v interface{}) ([]byte, error)
- func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error)
- func MarshalIndentContext(ctx context.Context, v interface{}, prefix, indent string) ([]byte, error)
- func MarshalToString(v interface{}) (string, error)
- func MarshalToStringContext(ctx context.Context, v interface{}) (string, error)
- func PtrElem(obj interface{}) reflect2.Type
- func RegisterExtension(extension Extension)
- func RegisterFieldDecoder(typ string, field string, decoder ValDecoder)
- func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc)
- func RegisterFieldEncoder(typ string, field string, encoder ValEncoder)
- func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, isEmptyFunc IsEmptyFn)
- func RegisterTypeDecoder(typ string, decoder ValDecoder)
- func RegisterTypeDecoderFunc(typ string, fun DecoderFunc)
- func RegisterTypeEncoder(typ string, encoder ValEncoder)
- func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc IsEmptyFn)
- func Unmarshal(data []byte, v interface{}) error
- func UnmarshalContext(ctx context.Context, data []byte, v interface{}) error
- func UnmarshalFromString(str string, v interface{}) error
- func UnmarshalFromStringContext(ctx context.Context, str string, v interface{}) error
- func Valid(data []byte) bool
- func ValidContext(ctx context.Context, data []byte) bool
- func ValidJSON(data []byte) bool
- func ValidJSONContext(ctx context.Context, s []byte) bool
- type API
- type Any
- type Binding
- type ClearJSON
- type Config
- type Decoder
- type DecoderExtension
- func (e DecoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder
- func (e DecoderExtension) CreateEncoder(reflect2.Type) ValEncoder
- func (e DecoderExtension) CreateMapKeyDecoder(reflect2.Type) ValDecoder
- func (e DecoderExtension) CreateMapKeyEncoder(reflect2.Type) ValEncoder
- func (e DecoderExtension) DecorateDecoder(_ reflect2.Type, v ValDecoder) ValDecoder
- func (e DecoderExtension) DecorateEncoder(_ reflect2.Type, v ValEncoder) ValEncoder
- func (e DecoderExtension) UpdateStructDescriptor(*StructDescriptor)
- type DecoderFunc
- type DummyExtension
- func (e *DummyExtension) CreateDecoder(reflect2.Type) ValDecoder
- func (e *DummyExtension) CreateEncoder(reflect2.Type) ValEncoder
- func (e *DummyExtension) CreateMapKeyDecoder(reflect2.Type) ValDecoder
- func (e *DummyExtension) CreateMapKeyEncoder(reflect2.Type) ValEncoder
- func (e *DummyExtension) DecorateDecoder(_ reflect2.Type, v ValDecoder) ValDecoder
- func (e *DummyExtension) DecorateEncoder(_ reflect2.Type, v ValEncoder) ValEncoder
- func (e *DummyExtension) UpdateStructDescriptor(*StructDescriptor)
- type Encoder
- type EncoderExtension
- func (e EncoderExtension) CreateDecoder(reflect2.Type) ValDecoder
- func (e EncoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder
- func (e EncoderExtension) CreateMapKeyDecoder(reflect2.Type) ValDecoder
- func (e EncoderExtension) CreateMapKeyEncoder(reflect2.Type) ValEncoder
- func (e EncoderExtension) DecorateDecoder(_ reflect2.Type, v ValDecoder) ValDecoder
- func (e EncoderExtension) DecorateEncoder(_ reflect2.Type, v ValEncoder) ValEncoder
- func (e EncoderExtension) UpdateStructDescriptor(*StructDescriptor)
- type EncoderFunc
- type Extension
- type Extensions
- type IsEmbeddedPtrNil
- type IsEmptyFn
- type Iterator
- func (iter *Iterator) CurrentBuffer() string
- func (iter *Iterator) Pool() IteratorPool
- func (iter *Iterator) Read(ctx context.Context) interface{}
- func (iter *Iterator) ReadAny() Any
- 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) ReadVal(ctx context.Context, obj interface{})
- 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 IteratorPool
- type MapEntryDecoder
- type MapEntryEncoder
- type MarshalerContext
- type Number
- type OptionalDecoder
- type OptionalEncoder
- type RawMessage
- type Stream
- func (s *Stream) Available() int
- func (s *Stream) Buffer() []byte
- func (s *Stream) Buffered() int
- func (s *Stream) Flush() error
- func (s *Stream) Pool() StreamPool
- func (s *Stream) Reset(out io.Writer)
- func (s *Stream) SetBuffer(buf []byte)
- func (s *Stream) Write(p []byte) (nn int, err error)
- func (s *Stream) WriteArrayEnd()
- func (s *Stream) WriteArrayStart()
- func (s *Stream) WriteBool(val bool)
- func (s *Stream) WriteEmptyArray()
- func (s *Stream) WriteEmptyObject()
- func (s *Stream) WriteFalse()
- func (s *Stream) WriteFloat32(val float32)
- func (s *Stream) WriteFloat32Lossy(val float32)
- func (s *Stream) WriteFloat64(val float64)
- func (s *Stream) WriteFloat64Lossy(val float64)
- func (s *Stream) WriteInt(val int)
- func (s *Stream) WriteInt16(nval int16)
- func (s *Stream) WriteInt32(nval int32)
- func (s *Stream) WriteInt64(nval int64)
- func (s *Stream) WriteInt8(nval int8)
- func (s *Stream) WriteMore()
- func (s *Stream) WriteNil()
- func (s *Stream) WriteObjectEnd()
- func (s *Stream) WriteObjectField(field string)
- func (s *Stream) WriteObjectStart()
- func (s *Stream) WriteRaw(a string)
- func (s *Stream) WriteRawBytes(a []byte)
- func (s *Stream) WriteString(a string)
- func (s *Stream) WriteStringWithHTMLEscaped(a string)
- func (s *Stream) WriteTrue()
- func (s *Stream) WriteUint(val uint)
- func (s *Stream) WriteUint16(val uint16)
- func (s *Stream) WriteUint32(val uint32)
- func (s *Stream) WriteUint64(val uint64)
- func (s *Stream) WriteUint8(val uint8)
- func (s *Stream) WriteVal(ctx context.Context, val interface{})
- type StreamPool
- type StructDescriptor
- type UnmarshalerContext
- type ValDecoder
- type ValEncoder
- type ValueType
Examples ¶
Constants ¶
const (
ContextCfg contextKey = iota
)
Variables ¶
var ConfigCompatibleWithStandardLibrary = Config{ EscapeHTML: true, SortMapKeys: true, ValidateJsonRawMessage: true, }.Froze()
ConfigCompatibleWithStandardLibrary tries to be 100% compatible with standard library behavior
var ConfigDefault = Config{ EscapeHTML: true, }.Froze()
ConfigDefault the default API
var ConfigFastest = Config{ EscapeHTML: false, MarshalFloatWith6Digits: true, ObjectFieldMustBeSimpleString: true, }.Froze()
ConfigFastest marshals float with only 6 digits precision
Functions ¶
func CastJsonNumber ¶
func Marshal ¶
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
Example ¶
type ColorGroup struct { ID int Name string Colors []string } group := ColorGroup{ ID: 1, Name: "Reds", Colors: []string{"Crimson", "Red", "Ruby", "Maroon"}, } b, err := Marshal(group) if err != nil { fmt.Println("error:", err) } fmt.Println(string(b)) var p *int b, err = json.Marshal(p) if err != nil { fmt.Println(err) return } fmt.Println(string(b)) b, err = Marshal(p) if err != nil { fmt.Println(err) return } fmt.Println(string(b))
Output: {"ID":1,"Name":"Reds","Colors":["Crimson","Red","Ruby","Maroon"]} null null
func MarshalIndent ¶
MarshalIndent same as json.MarshalIndent. Prefix is not supported.
func MarshalIndentContext ¶
func MarshalToString ¶
MarshalToString convenient method to write as string instead of []byte
func MarshalToStringContext ¶
func RegisterExtension ¶
func RegisterExtension(extension Extension)
RegisterExtension register extension
func RegisterFieldDecoder ¶
func RegisterFieldDecoder(typ string, field string, decoder ValDecoder)
RegisterFieldDecoder register TypeDecoder for a struct field
func RegisterFieldDecoderFunc ¶
func RegisterFieldDecoderFunc(typ string, field string, fun DecoderFunc)
RegisterFieldDecoderFunc register TypeDecoder for a struct field with function
func RegisterFieldEncoder ¶
func RegisterFieldEncoder(typ string, field string, encoder ValEncoder)
RegisterFieldEncoder register TypeEncoder for a struct field
func RegisterFieldEncoderFunc ¶
func RegisterFieldEncoderFunc(typ string, field string, fun EncoderFunc, isEmptyFunc IsEmptyFn)
RegisterFieldEncoderFunc register TypeEncoder for a struct field with encode/isEmpty function
func RegisterTypeDecoder ¶
func RegisterTypeDecoder(typ string, decoder ValDecoder)
RegisterTypeDecoder register TypeDecoder for a typ.
func RegisterTypeDecoderFunc ¶
func RegisterTypeDecoderFunc(typ string, fun DecoderFunc)
RegisterTypeDecoderFunc register TypeDecoder for a type with function
func RegisterTypeEncoder ¶
func RegisterTypeEncoder(typ string, encoder ValEncoder)
RegisterTypeEncoder register TypeEncoder for a type
func RegisterTypeEncoderFunc ¶
func RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc IsEmptyFn)
RegisterTypeEncoderFunc register TypeEncoder for a type with encode/isEmpty function
func Unmarshal ¶
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
Example ¶
jsonBlob := []byte(`[ {"Name": "Platypus", "Order": "Monotremata"}, {"Name": "Quoll", "Order": "Dasyuromorphia"} ]`) type Animal struct { Name string Order string } var animals []Animal err := Unmarshal(jsonBlob, &animals) if err != nil { fmt.Println("error:", err) } fmt.Printf("%+v\n", animals) type A struct { Bar string `json:"Bar"` } var a A c := Config{EscapeHTML: true, CaseSensitive: true}.Froze() c.Unmarshal(context.Background(), []byte(`{"Bar": "1", "bar": "2" }`), &a) fmt.Println(a.Bar)
Output: [{Name:Platypus Order:Monotremata} {Name:Quoll Order:Dasyuromorphia}] 1
func UnmarshalContext ¶
func UnmarshalFromString ¶
UnmarshalFromString is a convenient method to read from string instead of []byte
Types ¶
type API ¶
type API interface { IteratorPool StreamPool MarshalToString(ctx context.Context, v interface{}) (string, error) Marshal(ctx context.Context, v interface{}) ([]byte, error) MarshalIndent(ctx context.Context, v interface{}, prefix, indent string) ([]byte, error) UnmarshalFromString(ctx context.Context, str string, v interface{}) error Unmarshal(ctx context.Context, data []byte, v interface{}) error Get(data []byte, path ...interface{}) Any NewEncoder(writer io.Writer) *Encoder NewDecoder(reader io.Reader) *Decoder Valid(ctx context.Context, data []byte) bool RegisterExtension(extension Extension) DecoderOf(typ reflect2.Type) ValDecoder EncoderOf(typ reflect2.Type) ValEncoder RegisterTypeEncoder(typ string, encoder ValEncoder) RegisterTypeDecoder(typ string, decoder ValDecoder) RegisterTypeEncoderFunc(typ string, fun EncoderFunc, isEmptyFunc IsEmptyFn) RegisterTypeDecoderFunc(typ string, fun DecoderFunc) RegisterFieldEncoder(typ string, field string, encoder ValEncoder) RegisterFieldDecoder(typ string, field string, decoder ValDecoder) }
API the public interface of this package. Primary Marshal and Unmarshal.
type Any ¶
type Any interface { LastError() error ValueType() ValueType MustBeValid() Any ToBool() bool ToInt() int ToInt32() int32 ToInt64() int64 ToUint() uint ToUint32() uint32 ToUint64() uint64 ToFloat32() float32 ToFloat64() float64 ToString() string ToVal(ctx context.Context, val interface{}) Get(path ...interface{}) Any Size() int Keys() []string GetInterface(ctx context.Context) interface{} WriteTo(ctx context.Context, stream *Stream) }
Any generic object representation. The lazy json implementation holds []byte and parse lazily.
type Binding ¶
type Binding struct { Field reflect2.StructField FromNames []string ToNames []string Encoder ValEncoder Decoder ValDecoder // contains filtered or unexported fields }
Binding describe how should we encode/decode the struct field
type ClearJSON ¶
type ClearJSON struct {
Val interface{}
}
func AsClearJSON ¶
func AsClearJSON(v interface{}) *ClearJSON
type Config ¶
type Config struct { IndentionStep int MarshalFloatWith6Digits bool EscapeHTML bool SortMapKeys bool OmitEmptyStructField bool // omit empty struct field. OmitEmptyMapKeys bool // omit keys whose value is empty. UseNumber bool DisallowUnknownFields bool TagKey string OnlyTaggedField bool ValidateJsonRawMessage bool ObjectFieldMustBeSimpleString bool CaseSensitive bool Int64AsString bool NilAsEmpty bool ClearQuotes bool }
Config customize how the API should behave. The API is created from Config by Froze.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads and decodes JSON values from an input stream. Decoder provides identical APIs with json/stream Decoder (Token() and UseNumber() are in progress)
func NewDecoder ¶
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
func (*Decoder) DisallowUnknownFields ¶
func (a *Decoder) DisallowUnknownFields()
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.
type DecoderExtension ¶
type DecoderExtension map[reflect2.Type]ValDecoder
func (DecoderExtension) CreateDecoder ¶
func (e DecoderExtension) CreateDecoder(typ reflect2.Type) ValDecoder
CreateDecoder get decoder from map
func (DecoderExtension) CreateEncoder ¶
func (e DecoderExtension) CreateEncoder(reflect2.Type) ValEncoder
CreateEncoder No-op
func (DecoderExtension) CreateMapKeyDecoder ¶
func (e DecoderExtension) CreateMapKeyDecoder(reflect2.Type) ValDecoder
CreateMapKeyDecoder No-op
func (DecoderExtension) CreateMapKeyEncoder ¶
func (e DecoderExtension) CreateMapKeyEncoder(reflect2.Type) ValEncoder
CreateMapKeyEncoder No-op
func (DecoderExtension) DecorateDecoder ¶
func (e DecoderExtension) DecorateDecoder(_ reflect2.Type, v ValDecoder) ValDecoder
DecorateDecoder No-op
func (DecoderExtension) DecorateEncoder ¶
func (e DecoderExtension) DecorateEncoder(_ reflect2.Type, v ValEncoder) ValEncoder
DecorateEncoder No-op
func (DecoderExtension) UpdateStructDescriptor ¶
func (e DecoderExtension) UpdateStructDescriptor(*StructDescriptor)
UpdateStructDescriptor No-op
type DecoderFunc ¶
DecoderFunc the function form of TypeDecoder
type DummyExtension ¶
type DummyExtension struct{}
DummyExtension embed this type get dummy implementation for all methods of Extension
func (*DummyExtension) CreateDecoder ¶
func (e *DummyExtension) CreateDecoder(reflect2.Type) ValDecoder
CreateDecoder No-op
func (*DummyExtension) CreateEncoder ¶
func (e *DummyExtension) CreateEncoder(reflect2.Type) ValEncoder
CreateEncoder No-op
func (*DummyExtension) CreateMapKeyDecoder ¶
func (e *DummyExtension) CreateMapKeyDecoder(reflect2.Type) ValDecoder
CreateMapKeyDecoder No-op
func (*DummyExtension) CreateMapKeyEncoder ¶
func (e *DummyExtension) CreateMapKeyEncoder(reflect2.Type) ValEncoder
CreateMapKeyEncoder No-op
func (*DummyExtension) DecorateDecoder ¶
func (e *DummyExtension) DecorateDecoder(_ reflect2.Type, v ValDecoder) ValDecoder
DecorateDecoder No-op
func (*DummyExtension) DecorateEncoder ¶
func (e *DummyExtension) DecorateEncoder(_ reflect2.Type, v ValEncoder) ValEncoder
DecorateEncoder No-op
func (*DummyExtension) UpdateStructDescriptor ¶
func (e *DummyExtension) UpdateStructDescriptor(*StructDescriptor)
UpdateStructDescriptor No-op
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder same as json.Encoder
func (*Encoder) SetEscapeHTML ¶
SetEscapeHTML escape html by default, set to false to disable
type EncoderExtension ¶
type EncoderExtension map[reflect2.Type]ValEncoder
func (EncoderExtension) CreateDecoder ¶
func (e EncoderExtension) CreateDecoder(reflect2.Type) ValDecoder
CreateDecoder No-op
func (EncoderExtension) CreateEncoder ¶
func (e EncoderExtension) CreateEncoder(typ reflect2.Type) ValEncoder
CreateEncoder get encoder from map
func (EncoderExtension) CreateMapKeyDecoder ¶
func (e EncoderExtension) CreateMapKeyDecoder(reflect2.Type) ValDecoder
CreateMapKeyDecoder No-op
func (EncoderExtension) CreateMapKeyEncoder ¶
func (e EncoderExtension) CreateMapKeyEncoder(reflect2.Type) ValEncoder
CreateMapKeyEncoder No-op
func (EncoderExtension) DecorateDecoder ¶
func (e EncoderExtension) DecorateDecoder(_ reflect2.Type, v ValDecoder) ValDecoder
DecorateDecoder No-op
func (EncoderExtension) DecorateEncoder ¶
func (e EncoderExtension) DecorateEncoder(_ reflect2.Type, v ValEncoder) ValEncoder
DecorateEncoder No-op
func (EncoderExtension) UpdateStructDescriptor ¶
func (e EncoderExtension) UpdateStructDescriptor(*StructDescriptor)
UpdateStructDescriptor No-op
type EncoderFunc ¶
EncoderFunc the function form of TypeEncoder
func CreateTimeEncodeFn ¶
func CreateTimeEncodeFn(layout string) EncoderFunc
CreateTimeEncodeFn creates a time.Time encoding function on the specified layout.
type Extension ¶
type Extension interface { UpdateStructDescriptor(structDescriptor *StructDescriptor) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder CreateMapKeyEncoder(typ reflect2.Type) ValEncoder CreateDecoder(typ reflect2.Type) ValDecoder CreateEncoder(typ reflect2.Type) ValEncoder DecorateDecoder(typ reflect2.Type, decoder ValDecoder) ValDecoder DecorateEncoder(typ reflect2.Type, encoder ValEncoder) ValEncoder }
type Extensions ¶
type Extensions []Extension
func (Extensions) CreateMapKeyDecoder ¶
func (es Extensions) CreateMapKeyDecoder(typ reflect2.Type) ValDecoder
func (Extensions) CreateMapKeyEncoder ¶
func (es Extensions) CreateMapKeyEncoder(typ reflect2.Type) ValEncoder
func (Extensions) UpdateStructDescriptor ¶
func (es Extensions) UpdateStructDescriptor(structDescriptor *StructDescriptor)
type IsEmbeddedPtrNil ¶
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 NewIterator ¶
NewIterator creates an empty 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) Pool ¶
func (iter *Iterator) Pool() IteratorPool
Pool returns a pool can provide more iterator with same configuration
func (*Iterator) ReadAny ¶
ReadAny read next JSON element as an Any object. It is a better json.RawMessage.
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) ReadVal ¶
ReadVal copy the underlying JSON into go interface, same as json.Unmarshal
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 IteratorPool ¶
type IteratorPool interface { BorrowIterator(data []byte) *Iterator ReturnIterator(iter *Iterator) }
IteratorPool a thread safe pool of iterators with same configuration
type MapEntryDecoder ¶
type MapEntryDecoder interface {
EntryDecoder() (keyDecoder, elemDecoder ValDecoder)
}
type MapEntryEncoder ¶
type MapEntryEncoder interface {
EntryEncoder() (keyEncoder, elemEncoder ValEncoder)
}
type MarshalerContext ¶
MarshalerContext is the interface implemented by types that can marshal themselves into valid JSON with context.Context.
type OptionalDecoder ¶
type OptionalDecoder struct { ValueType reflect2.Type ValueDecoder ValDecoder }
type OptionalEncoder ¶
type OptionalEncoder struct {
ValueEncoder ValEncoder
}
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 jsoni.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) Pool ¶
func (s *Stream) Pool() StreamPool
Pool returns a pool can provide more stream with same configuration
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 (s *Stream) WriteArrayEnd()
WriteArrayEnd write ] with possible indention
func (*Stream) WriteArrayStart ¶
func (s *Stream) WriteArrayStart()
WriteArrayStart write [ with possible indention
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) WriteObjectEnd ¶
func (s *Stream) WriteObjectEnd()
WriteObjectEnd write } with possible indention
func (*Stream) WriteObjectField ¶
WriteObjectField write "field": with possible indention
func (*Stream) WriteObjectStart ¶
func (s *Stream) WriteObjectStart()
WriteObjectStart write { with possible indention
func (*Stream) WriteRawBytes ¶
WriteRawBytes write string out without quotes, just like []byte
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
type StreamPool ¶
StreamPool a thread safe pool of streams with same configuration
type StructDescriptor ¶
StructDescriptor describe how should we encode/decode the struct
func (*StructDescriptor) GetField ¶
func (structDescriptor *StructDescriptor) GetField(fieldName string) *Binding
GetField get one field from the descriptor by its name. Can not use map here to keep field orders.
type UnmarshalerContext ¶
UnmarshalerContext is the interface implemented by types that can unmarshal with context.Context a JSON description of themselves.
type ValDecoder ¶
ValDecoder is an internal type registered to cache as needed. Don't confuse jsoni.ValDecoder with json.Decoder. For json.Decoder's adapter, refer to jsoni.AdapterDecoder(todo link).
Reflection on type to create decoders, which is then cached Reflection on value is avoided as we can, as the reflect.Value itself will allocate, with following exceptions 1. create instance of new value, for example *int will need a int to be allocated 2. append to slice, if the existing cap is not enough, allocate will be done using Reflect.New 3. assignment to map, both key and value will be reflect.Value For a simple struct binding, it will be reflect.Value free and allocation free
type ValEncoder ¶
type ValEncoder interface { IsEmpty(ctx context.Context, ptr unsafe.Pointer, checkZero bool) bool Encode(ctx context.Context, ptr unsafe.Pointer, stream *Stream) }
ValEncoder is an internal type registered to cache as needed. Don't confuse jsoni.ValEncoder with json.Encoder. For json.Encoder's adapter, refer to jsoni.AdapterEncoder(todo godoc link).
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 )
Source Files ¶
- adapter.go
- any.go
- any_array.go
- any_bool.go
- any_float.go
- any_int32.go
- any_int64.go
- any_invalid.go
- any_nil.go
- any_number.go
- any_object.go
- any_str.go
- any_uint32.go
- any_uint64.go
- clear.go
- config.go
- iter.go
- iter_array.go
- iter_float.go
- iter_int.go
- iter_object.go
- iter_skip.go
- iter_skip_strict.go
- iter_str.go
- jsoni.go
- pool.go
- reflect.go
- reflect_array.go
- reflect_dynamic.go
- reflect_extension.go
- reflect_json_number.go
- reflect_json_raw_message.go
- reflect_map.go
- reflect_marshaler.go
- reflect_native.go
- reflect_optional.go
- reflect_slice.go
- reflect_struct_decoder.go
- reflect_struct_encoder.go
- stream.go
- stream_float.go
- stream_int.go
- stream_str.go