# README
A high-performance 100% compatible drop-in replacement of "encoding/json"
Benchmark
Raw Result (easyjson requires static code generation)
ns/op | allocation bytes | allocation times | |
---|---|---|---|
std decode | 35510 ns/op | 1960 B/op | 99 allocs/op |
easyjson decode | 8499 ns/op | 160 B/op | 4 allocs/op |
jsoniter decode | 5623 ns/op | 160 B/op | 3 allocs/op |
std encode | 2213 ns/op | 712 B/op | 5 allocs/op |
easyjson encode | 883 ns/op | 576 B/op | 3 allocs/op |
jsoniter encode | 837 ns/op | 384 B/op | 4 allocs/op |
Always benchmark with your own workload. The result depends heavily on the data input.
Usage
100% compatibility with standard lib
Replace
import "encoding/json"
json.Marshal(&data)
with
import jsoniter "github.com/json-iterator/go"
var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Marshal(&data)
Replace
import "encoding/json"
json.Unmarshal(input, &data)
with
import jsoniter "github.com/json-iterator/go"
var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(input, &data)
How to get
go get github.com/json-iterator/go
Contribution Welcomed !
Contributors
Report issue or pull request, or email [email protected], or
# Functions
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.
MarshalToString convenient method to write as string instead of []byte.
NewDecoder adapts to json/stream NewDecoder API.
NewEncoder same as json.NewEncoder.
NewIterator creates an empty Iterator instance.
NewStream create new stream instance.
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.
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.
# Constants
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".
# Variables
ConfigCompatibleWithStandardLibrary tries to be 100% compatible with standard library behavior.
ConfigDefault the default API.
ConfigFastest marshals float with only 6 digits precision.
# Structs
Binding describe how should we encode/decode the struct field.
Config customize how the API should behave.
Decoder reads and decodes JSON values from an input stream.
DummyExtension embed this type get dummy implementation for all methods of Extension.
Encoder same as json.Encoder.
Iterator is a io.Reader like object, with JSON specific read functions.
stream is a io.Writer like object, with JSON specific write functions.
StructDescriptor describe how should we encode/decode the struct.
# Interfaces
Any generic object representation.
API the public interface of this package.
Extension the one for all SPI.
IteratorPool a thread safe pool of iterators with same configuration.
StreamPool a thread safe pool of streams with same configuration.
ValDecoder is an internal type registered to cache as needed.
ValEncoder is an internal type registered to cache as needed.
# Type aliases
DecoderFunc the function form of TypeDecoder.
EncoderFunc the function form of TypeEncoder.
RawMessage to make replace json with jsoniter.
ValueType the type for JSON element.