ujson

package module
v0.0.0-...-c02629f Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: MIT Imports: 6 Imported by: 2

README

go-ujson

A pure Go port of ultrajson with a go-simplejson like interface.

$ go test -bench ".*"
PASS
BenchmarkUjson	  500000	      4970 ns/op	  20.12 MB/s
BenchmarkStdLib	  200000	     10323 ns/op	   9.69 MB/s

WARNING: very early stages of a public API

Documentation

Overview

copied (almost) entirely from the Go standard library, encoding/json/decode.go

Index

Constants

View Source
const (
	JT_NULL = iota
	JT_TRUE
	JT_FALSE
	JT_NUMERIC
	JT_UTF8
	JT_ARRAY
	JT_OBJECT
	JT_INVALID
)
View Source
const (
	SS_NORMAL = iota
	SS_ESC
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

func NewDecoder

func NewDecoder(store ObjectStore, data []byte) *Decoder

func (*Decoder) Decode

func (j *Decoder) Decode() (interface{}, error)

type JSON

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

func NewFromBytes

func NewFromBytes(data []byte) (*JSON, error)

func (*JSON) Array

func (j *JSON) Array(args ...[]interface{}) []*JSON

Array guarantees the return of an `[]*JSON` (with optional default)

useful when you explicitly want an `bool` in a single value return context:

myFunc(js.Get("param1").Array(), js.Get("optional_param").Array([]interface{}{"string", 1, 1.1, false}))

func (*JSON) Bool

func (j *JSON) Bool(args ...bool) bool

Bool guarantees the return of an `bool` (with optional default)

useful when you explicitly want an `bool` in a single value return context:

myFunc(js.Get("param1").Bool(), js.Get("optional_param").Bool(true))

func (*JSON) Float64

func (j *JSON) Float64(args ...float64) float64

Float64 guarantees the return of an `float64` (with optional default)

useful when you explicitly want an `float64` in a single value return context:

myFunc(js.Get("param1").Float64(), js.Get("optional_param").Float64(51.15))

func (*JSON) Get

func (j *JSON) Get(key string) *JSON

Get returns a pointer to a new `Json` object for `key` in its `map` representation

useful for chaining operations (to traverse a nested JSON):

js.Get("top_level").Get("dict").Get("value").Int()

func (*JSON) Int64

func (j *JSON) Int64(args ...int64) int64

Int64 guarantees the return of an `int64` (with optional default)

useful when you explicitly want an `int64` in a single value return context:

myFunc(js.Get("param1").Int64(), js.Get("optional_param").Int64(5150))

func (*JSON) Interface

func (j *JSON) Interface() interface{}

func (*JSON) Map

func (j *JSON) Map(args ...map[string]interface{}) map[string]interface{}

Map guarantees the return of a `map[string]interface{}` (with optional default)

useful when you want to interate over map values in a succinct manner:

for k, v := range js.Get("dictionary").Map() {
	fmt.Println(k, v)
}

func (*JSON) MaybeArray

func (j *JSON) MaybeArray() ([]*JSON, error)

MaybeArray type asserts to `*[]interface{}`

func (*JSON) MaybeBool

func (j *JSON) MaybeBool() (bool, error)

MaybeBool type asserts and parses an `bool`

func (*JSON) MaybeFloat64

func (j *JSON) MaybeFloat64() (float64, error)

MaybeFloat64 type asserts and parses an `float64`

func (*JSON) MaybeInt64

func (j *JSON) MaybeInt64() (int64, error)

MaybeInt64 type asserts and parses an `int64`

func (*JSON) MaybeMap

func (j *JSON) MaybeMap() (map[string]interface{}, error)

MaybeMap type asserts to `map`

func (*JSON) MaybeString

func (j *JSON) MaybeString() (string, error)

MaybeString type asserts to `string`

func (*JSON) String

func (j *JSON) String(args ...string) string

String guarantees the return of a `string` (with optional default)

useful when you explicitly want a `string` in a single value return context:

myFunc(js.Get("param1").String(), js.Get("optional_param").String("my_default"))

type ObjectStore

type ObjectStore interface {
	NewObject() (interface{}, error)
	NewArray() (interface{}, error)
	ObjectAddKey(interface{}, interface{}, interface{}) error
	ArrayAddItem(interface{}, interface{}) error
	NewString([]byte) (interface{}, error)
	NewNumeric([]byte) (interface{}, error)
	NewTrue() (interface{}, error)
	NewFalse() (interface{}, error)
	NewNull() (interface{}, error)
}

Jump to

Keyboard shortcuts

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