json

package module
v0.0.0-...-6b510c2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2016 License: Apache-2.0 Imports: 6 Imported by: 6

README

json

This project implements a read-only JSON parser in Go

This file provides a custom JSON parser suitable for processing Twitter data. Some differences from the standard Golang json package:

  • Parses numbers into int64 where possible, float64 otherwise.
  • Faster! Probably due to less reflection:

Real-world Tweet example (Std is encoding/json):

BenchmarkStdJSON          10000    158362 ns/op
BenchmarkJSON             10000    122690 ns/op

The following numbers use a contrived small example. Untyped unmarshals into an []interface{} while Bucket unmarshals into a type using reflection:

BenchmarkStdBucket       200000     10781 ns/op
BenchmarkBucket          500000      5455 ns/op
BenchmarkUntypedBucket  1000000      2747 ns/op

This library also performs escaped UTF-8 entity decoding on strings, so you get the raw runes instead of escaped \u#### sequences.

Maturity

This is a relatively new JSON parser so there's certainly edge cases which may throw errors or otherwise parse incorrectly. Please file bugs / submit tests! I'm happy to fix issues.

That being said, this library is very compatible with Twitter's JSON encoding. It has been able to parse messages from Twitter's 1% stream for hours without issue.

Installing

Run

go get github.com/kurrik/json

Include in your source:

import "github.com/kurrik/json"

Updating

Run

go get -u github.com/kurrik/json

Benchmarking

go test -bench=".*"

Testing

Most edge cases are tested in compat_test.go. Please add cases if you find any!

Documentation

Index

Constants

View Source
const (
	STRING = iota
	NUMBER
	MAP
	ARRAY
	ENDARRAY
	ESCAPE
	BOOL
	NULL
)

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Types

type EndArray

type EndArray struct{}

func (EndArray) Error

func (e EndArray) Error() string

type EndMap

type EndMap struct{}

func (EndMap) Error

func (e EndMap) Error() string

type Event

type Event struct {
	Type  int
	Index int
}

type State

type State struct {
	// contains filtered or unexported fields
}

func (*State) Read

func (s *State) Read() (err error)

Jump to

Keyboard shortcuts

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