simplejson

package module
v0.0.0-...-1c4a2a7 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2013 License: MIT Imports: 3 Imported by: 4 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-simplejson

a Go package to interact with arbitrary JSON

Importing

import simplejson github.com/jgranstrom/go-simplejson

Documentation

Visit the docs on gopkgdoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version() string

returns the current implementation version

Types

type Json

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

func Create

func Create(data interface{}) *Json

Create a Json object

func MakeMap

func MakeMap() (j *Json, m map[string]interface{}, err error)

Make a Json and assert as a map[string]interface{}

func NewJson

func NewJson(body []byte) (*Json, error)

NewJson returns a pointer to a new `Json` object after unmarshaling `body` bytes

func (*Json) Array

func (j *Json) Array() ([]interface{}, error)

Array type asserts to an `array`

func (*Json) Bool

func (j *Json) Bool() (bool, error)

Bool type asserts to `bool`

func (*Json) Bytes

func (j *Json) Bytes() ([]byte, error)

Bytes type asserts to `[]byte`

func (*Json) CheckGet

func (j *Json) CheckGet(key string) (*Json, bool)

CheckGet returns a pointer to a new `Json` object and a `bool` identifying success or failure

useful for chained operations when success is important:

if data, ok := js.Get("top_level").CheckGet("inner"); ok {
    log.Println(data)
}

func (*Json) Encode

func (j *Json) Encode() ([]byte, error)

Encode returns its marshaled data as `[]byte`

func (*Json) Float64

func (j *Json) Float64() (float64, error)

Float64 type asserts to `float64`

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) GetIndex

func (j *Json) GetIndex(index int) *Json

GetIndex resturns a pointer to a new `Json` object for `index` in its `array` representation

this is the analog to Get when accessing elements of a json array instead of a json object:

js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()

func (*Json) Int

func (j *Json) Int() (int, error)

Int type asserts to `float64` then converts to `int`

func (*Json) Int64

func (j *Json) Int64() (int64, error)

Int type asserts to `float64` then converts to `int64`

func (*Json) IntArray

func (j *Json) IntArray() ([]int, error)

IntArray type asserts to an `array` of `int`

func (*Json) Map

func (j *Json) Map() (map[string]interface{}, error)

Map type asserts to `map`

func (*Json) MarshalJSON

func (j *Json) MarshalJSON() ([]byte, error)

Implements the json.Marshaler interface.

func (*Json) MustFloat64

func (j *Json) MustFloat64(args ...float64) float64

MustFloat64 guarantees the return of a `float64` (with optional default)

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

myFunc(js.Get("param1").MustFloat64(), js.Get("optional_param").MustFloat64(5.150))

func (*Json) MustInt

func (j *Json) MustInt(args ...int) int

MustInt guarantees the return of an `int` (with optional default)

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

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

func (*Json) MustString

func (j *Json) MustString(args ...string) string

MustString 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").MustString(), js.Get("optional_param").MustString("my_default"))

func (*Json) String

func (j *Json) String() (string, error)

String type asserts to `string`

func (*Json) StringArray

func (j *Json) StringArray() ([]string, error)

StringArray type asserts to an `array` of `string`

func (*Json) UnmarshalJSON

func (j *Json) UnmarshalJSON(p []byte) error

Implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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