Documentation ¶
Overview ¶
Package sjson provides fast and simple JSON decoder.
Sjson is designed to be fast and simple, for now it supports only dynamic deserialization. It can decode JSON Text as defined in ECMA-404. Simple benchmark test shows ~2x speedup against encoding/json standard parser.
$ go test -bench=Sample\|Code -benchtime=5s BenchmarkSample_sjson 1000000 7582 ns/op 87.43 MB/s // Equivalent of our production JSON BenchmarkSample__json 300000 19579 ns/op 33.86 MB/s BenchmarkCode_sjson 300 28384877 ns/op 68.36 MB/s // JSON Text from the encoding/json package BenchmarkCode__json 100 60002297 ns/op 32.34 MB/s
Thanks ¶
Development of the project was sponsored by CP Decision Limited (http://cpdecision.com) as part of a project on processing statistical data.
Some ideas was borrowed from excellent Marc A. Lehmann's JSON::XS code.
Example ¶
data := `{"name":"John","age":30}` obj, err := sjson.Decode(data) if err != nil { panic(err) } fmt.Printf("Hi, %s!\n", obj.(map[string]interface{})["name"])
Output: Hi, John!
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var PreallocateObjectElems = 2
PreallocateObjectElems parameter allow to tune preallocated memory objects during the parsing process.
Functions ¶
Types ¶
type SyntaxError ¶
type SyntaxError struct { Offset int // current parser position at which the error occurred // contains filtered or unexported fields }
A SyntaxError is a description of a JSON syntax error.
func (*SyntaxError) Error ¶
func (e *SyntaxError) Error() string
Click to show internal directories.
Click to hide internal directories.