sjson

package module
v0.0.0-...-57b3aae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2015 License: MIT Imports: 5 Imported by: 0

README

go-sjson

Fast and simple JSON parser for Go

Package sjson provides decoding of JSON Text as defined in ECMA-404. Sjson designed to be fast and simple, for now it supports only dynamic deserialization. Simple benchmark 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

Some useful links.

Thanks

Development of the project was sponsored by CP Decision Limited as part of a project on processing statistical data.

Some ideas was borrowed from excellent Marc A. Lehmanns JSON::XS code.

License

Licensed in terms of MIT license (see https://github.com/vovkasm/go-sjson/blob/master/LICENSE.md file).

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

func Decode

func Decode(json string) (interface{}, error)

Decode function parse JSON Text into interface value. Rules are the same as in encoding/json module:

bool, for JSON booleans
float64, for JSON numbers
string, for JSON strings
[]interface{}, for JSON arrays
map[string]interface{}, for JSON objects
nil, for JSON null

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL