gabs

package
v0.0.0-...-2c4df64 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2018 License: LGPL-3.0, MIT Imports: 9 Imported by: 0

README

Gabs

Gabs is a small utility for dealing with dynamic or unknown JSON structures in golang. It's pretty much just a helpful wrapper around the golang json.Marshal/json.Unmarshal behaviour and map[string]interface{} objects. It does nothing spectacular except for being fabulous.

https://godoc.org/github.com/Jeffail/gabs

How to install:

go get github.com/Jeffail/gabs

How to use

Parsing and searching JSON

...

import "github.com/Jeffail/gabs"

jsonParsed, err := gabs.ParseJSON([]byte(`{
	"outter":{
		"inner":{
			"value1":10,
			"value2":22
		},
		"alsoInner":{
			"value1":20
		}
	}
}`))

var value float64
var ok bool

value, ok = jsonParsed.Path("outter.inner.value1").Data().(float64)
// value == 10.0, ok == true

value, ok = jsonParsed.Search("outter", "inner", "value1").Data().(float64)
// value == 10.0, ok == true

value, ok = jsonParsed.Path("does.not.exist").Data().(float64)
// value == 0.0, ok == false

exists := jsonParsed.Exists("outter", "inner", "value1")
// exists == true

exists := jsonParsed.Exists("does", "not", "exist")
// exists == false

exists := jsonParsed.ExistsP("does.not.exist")
// exists == false

...

Iterating objects

...

jsonParsed, _ := gabs.ParseJSON([]byte(`{"object":{ "first": 1, "second": 2, "third": 3 }}`))

// S is shorthand for Search
children, _ := jsonParsed.S("object").ChildrenMap()
for key, child := range children {
	fmt.Printf("key: %v, value: %v\n", key, child.Data().(string))
}

...

Iterating arrays

...

jsonParsed, _ := gabs.ParseJSON([]byte(`{"array":[ "first", "second", "third" ]}`))

// S is shorthand for Search
children, _ := jsonParsed.S("array").Children()
for _, child := range children {
	fmt.Println(child.Data().(string))
}

...

Will print:

first
second
third

Children() will return all children of an array in order. This also works on objects, however, the children will be returned in a random order.

Searching through arrays

If your JSON structure contains arrays you can still search the fields of the objects within the array, this returns a JSON array containing the results for each element.

...

jsonParsed, _ := gabs.ParseJSON([]byte(`{"array":[ {"value":1}, {"value":2}, {"value":3} ]}`))
fmt.Println(jsonParsed.Path("array.value").String())

...

Will print:

[1,2,3]

Generating JSON

...

jsonObj := gabs.New()
// or gabs.Consume(jsonObject) to work on an existing map[string]interface{}

jsonObj.Set(10, "outter", "inner", "value")
jsonObj.SetP(20, "outter.inner.value2")
jsonObj.Set(30, "outter", "inner2", "value3")

fmt.Println(jsonObj.String())

...

Will print:

{"outter":{"inner":{"value":10,"value2":20},"inner2":{"value3":30}}}

To pretty-print:

...

fmt.Println(jsonObj.StringIndent("", "  "))

...

Will print:

{
  "outter": {
    "inner": {
      "value": 10,
      "value2": 20
    },
    "inner2": {
      "value3": 30
    }
  }
}

Generating Arrays

...

jsonObj := gabs.New()

jsonObj.Array("foo", "array")
// Or .ArrayP("foo.array")

jsonObj.ArrayAppend(10, "foo", "array")
jsonObj.ArrayAppend(20, "foo", "array")
jsonObj.ArrayAppend(30, "foo", "array")

fmt.Println(jsonObj.String())

...

Will print:

{"foo":{"array":[10,20,30]}}

Working with arrays by index:

...

jsonObj := gabs.New()

// Create an array with the length of 3
jsonObj.ArrayOfSize(3, "foo")

jsonObj.S("foo").SetIndex("test1", 0)
jsonObj.S("foo").SetIndex("test2", 1)

// Create an embedded array with the length of 3
jsonObj.S("foo").ArrayOfSizeI(3, 2)

jsonObj.S("foo").Index(2).SetIndex(1, 0)
jsonObj.S("foo").Index(2).SetIndex(2, 1)
jsonObj.S("foo").Index(2).SetIndex(3, 2)

fmt.Println(jsonObj.String())

...

Will print:

{"foo":["test1","test2",[1,2,3]]}

Converting back to JSON

This is the easiest part:

...

jsonParsedObj, _ := gabs.ParseJSON([]byte(`{
	"outter":{
		"values":{
			"first":10,
			"second":11
		}
	},
	"outter2":"hello world"
}`))

jsonOutput := jsonParsedObj.String()
// Becomes `{"outter":{"values":{"first":10,"second":11}},"outter2":"hello world"}`

...

And to serialize a specific segment is as simple as:

...

jsonParsedObj := gabs.ParseJSON([]byte(`{
	"outter":{
		"values":{
			"first":10,
			"second":11
		}
	},
	"outter2":"hello world"
}`))

jsonOutput := jsonParsedObj.Search("outter").String()
// Becomes `{"values":{"first":10,"second":11}}`

...

Merge two containers

You can merge a JSON structure into an existing one, where collisions will be converted into a JSON array.

jsonParsed1, _ := ParseJSON([]byte(`{"outter": {"value1": "one"}}`))
jsonParsed2, _ := ParseJSON([]byte(`{"outter": {"inner": {"value3": "three"}}, "outter2": {"value2": "two"}}`))

jsonParsed1.Merge(jsonParsed2)
// Becomes `{"outter":{"inner":{"value3":"three"},"value1":"one"},"outter2":{"value2":"two"}}`

Arrays are merged:

jsonParsed1, _ := ParseJSON([]byte(`{"array": ["one"]}`))
jsonParsed2, _ := ParseJSON([]byte(`{"array": ["two"]}`))

jsonParsed1.Merge(jsonParsed2)
// Becomes `{"array":["one", "two"]}`

Parsing Numbers

Gabs uses the json package under the bonnet, which by default will parse all number values into float64. If you need to parse Int values then you should use a json.Decoder (https://golang.org/pkg/encoding/json/#Decoder):

sample := []byte(`{"test":{"int":10, "float":6.66}}`)
dec := json.NewDecoder(bytes.NewReader(sample))
dec.UseNumber()

val, err := gabs.ParseJSONDecoder(dec)
if err != nil {
    t.Errorf("Failed to parse: %v", err)
    return
}

intValue, err := val.Path("test.int").Data().(json.Number).Int64()

Documentation

Overview

Code generated by "ext_gen.go ; DO NOT EDIT.

Package gabs implements a simplified wrapper around creating and parsing JSON.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrOutOfBounds - Index out of bounds.
	ErrOutOfBounds = errors.New("out of bounds")

	// ErrNotObjOrArray - The target is not an object or array type.
	ErrNotObjOrArray = errors.New("not an object or array")

	// ErrNotObj - The target is not an object type.
	ErrNotObj = errors.New("not an object")

	// ErrNotArray - The target is not an array type.
	ErrNotArray = errors.New("not an array")

	// ErrPathCollision - Creating a path failed because an element collided with an existing value.
	ErrPathCollision = errors.New("encountered value collision whilst building path")

	// ErrInvalidInputObj - The input value was not a map[string]interface{}.
	ErrInvalidInputObj = errors.New("invalid input object")

	// ErrInvalidInputText - The input data could not be parsed.
	ErrInvalidInputText = errors.New("input text could not be parsed")

	// ErrInvalidPath - The filepath was not valid.
	ErrInvalidPath = errors.New("invalid file path")

	// ErrInvalidBuffer - The input buffer contained an invalid JSON string
	ErrInvalidBuffer = errors.New("input buffer contained invalid JSON")
)

Functions

This section is empty.

Types

type Container

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

Container - an internal structure that holds a reference to the core interface map of the parsed json. Use this container to move context.

func Consume

func Consume(root interface{}) (*Container, error)

Consume - Gobble up an already converted JSON object, or a fresh map[string]interface{} object.

func MustParseJSON

func MustParseJSON(data []byte) *Container

func MustParseObject

func MustParseObject(data interface{}) (r *Container)

func New

func New() *Container

New - Create a new gabs JSON object.

func ParseJSON

func ParseJSON(sample []byte) (*Container, error)

ParseJSON - Convert a string into a representation of the parsed JSON.

func ParseJSONBuffer

func ParseJSONBuffer(buffer io.Reader) (*Container, error)

ParseJSONBuffer - Read the contents of a buffer into a representation of the parsed JSON.

func ParseJSONDecoder

func ParseJSONDecoder(decoder *json.Decoder) (*Container, error)

ParseJSONDecoder - Convert a json.Decoder into a representation of the parsed JSON.

func ParseJSONFile

func ParseJSONFile(path string) (*Container, error)

ParseJSONFile - Read a file and convert into a representation of the parsed JSON.

func ParseMsgPack

func ParseMsgPack(sample []byte) (*Container, error)

func ParseMsgPackBuffer

func ParseMsgPackBuffer(buffer io.Reader) (*Container, error)

func ParseMsgPackDecoder

func ParseMsgPackDecoder(decoder *codec.Decoder) (*Container, error)

func ParseMsgPackFile

func ParseMsgPackFile(path string) (*Container, error)

func ParseObject

func ParseObject(data interface{}) (*Container, error)

func (*Container) Array

func (g *Container) Array(path ...string) (*Container, error)

Array - Create a new JSON array at a path. Returns an error if the path contains a collision with a non object type.

func (*Container) ArrayAppend

func (g *Container) ArrayAppend(value interface{}, path ...string) error

ArrayAppend - Append a value onto a JSON array. If the target is not a JSON array then it will be converted into one, with its contents as the first element of the array.

func (*Container) ArrayAppendP

func (g *Container) ArrayAppendP(value interface{}, path string) error

ArrayAppendP - Append a value onto a JSON array using a dot notation JSON path.

func (*Container) ArrayCount

func (g *Container) ArrayCount(path ...string) (int, error)

ArrayCount - Count the number of elements in a JSON array.

func (*Container) ArrayCountP

func (g *Container) ArrayCountP(path string) (int, error)

ArrayCountP - Count the number of elements in a JSON array using a dot notation JSON path.

func (*Container) ArrayElement

func (g *Container) ArrayElement(index int, path ...string) (*Container, error)

ArrayElement - Access an element from a JSON array.

func (*Container) ArrayElementP

func (g *Container) ArrayElementP(index int, path string) (*Container, error)

ArrayElementP - Access an element from a JSON array using a dot notation JSON path.

func (*Container) ArrayI

func (g *Container) ArrayI(index int) (*Container, error)

ArrayI - Create a new JSON array at an array index. Returns an error if the object is not an array or the index is out of bounds.

func (*Container) ArrayOfSize

func (g *Container) ArrayOfSize(size int, path ...string) (*Container, error)

ArrayOfSize - Create a new JSON array of a particular size at a path. Returns an error if the path contains a collision with a non object type.

func (*Container) ArrayOfSizeI

func (g *Container) ArrayOfSizeI(size, index int) (*Container, error)

ArrayOfSizeI - Create a new JSON array of a particular size at an array index. Returns an error if the object is not an array or the index is out of bounds.

func (*Container) ArrayOfSizeP

func (g *Container) ArrayOfSizeP(size int, path string) (*Container, error)

ArrayOfSizeP - Does the same as ArrayOfSize, but using a dot notation JSON path.

func (*Container) ArrayP

func (g *Container) ArrayP(path string) (*Container, error)

ArrayP - Does the same as Array, but using a dot notation JSON path.

func (*Container) ArrayRemove

func (g *Container) ArrayRemove(index int, path ...string) error

ArrayRemove - Remove an element from a JSON array.

func (*Container) ArrayRemoveP

func (g *Container) ArrayRemoveP(index int, path string) error

ArrayRemoveP - Remove an element from a JSON array using a dot notation JSON path.

func (*Container) Bytes

func (g *Container) Bytes() []byte

Bytes - Converts the contained object back to a JSON []byte blob.

func (*Container) BytesIndent

func (g *Container) BytesIndent(prefix string, indent string) []byte

BytesIndent - Converts the contained object to a JSON []byte blob formatted with prefix, indent.

func (*Container) Children

func (g *Container) Children() ([]*Container, error)

Children - Return a slice of all the children of the array. This also works for objects, however, the children returned for an object will NOT be in order and you lose the names of the returned objects this way.

func (*Container) ChildrenMap

func (g *Container) ChildrenMap() (map[string]*Container, error)

ChildrenMap - Return a map of all the children of an object.

func (*Container) ContainsPath

func (g *Container) ContainsPath(path ...string) bool

func (*Container) Data

func (g *Container) Data() interface{}

Data - Return the contained data as an interface{}.

func (*Container) Delete

func (g *Container) Delete(path ...string) error

Delete - Delete an element at a JSON path, an error is returned if the element does not exist.

func (*Container) DeleteP

func (g *Container) DeleteP(path string) error

DeleteP - Does the same as Delete, but using a dot notation JSON path.

func (*Container) EncodeJSON

func (g *Container) EncodeJSON(encodeOpts ...EncodeOpt) []byte

EncodeJSON - Encodes the contained object back to a JSON formatted []byte using a variant list of modifier functions for the encoder being used. Functions for modifying the output are prefixed with EncodeOpt, e.g. EncodeOptHTMLEscape.

func (*Container) Exists

func (g *Container) Exists(hierarchy ...string) bool

Exists - Checks whether a path exists.

func (*Container) ExistsP

func (g *Container) ExistsP(path string) bool

ExistsP - Checks whether a dot notation path exists.

func (*Container) GetBool

func (g *Container) GetBool(path ...string) (bool, error)

func (*Container) GetBoolP

func (g *Container) GetBoolP(path string) (bool, error)

func (*Container) GetBoolSlice

func (g *Container) GetBoolSlice(path ...string) ([]bool, error)

func (*Container) GetBoolSliceP

func (g *Container) GetBoolSliceP(path string) ([]bool, error)

func (*Container) GetByteSlice

func (g *Container) GetByteSlice(path ...string) ([]byte, error)

func (*Container) GetByteSliceP

func (g *Container) GetByteSliceP(path string) ([]byte, error)

func (*Container) GetFloat32

func (g *Container) GetFloat32(path ...string) (float32, error)

func (*Container) GetFloat32P

func (g *Container) GetFloat32P(path string) (float32, error)

func (*Container) GetFloat32Slice

func (g *Container) GetFloat32Slice(path ...string) ([]float32, error)

func (*Container) GetFloat32SliceP

func (g *Container) GetFloat32SliceP(path string) ([]float32, error)

func (*Container) GetFloat64

func (g *Container) GetFloat64(path ...string) (float64, error)

func (*Container) GetFloat64P

func (g *Container) GetFloat64P(path string) (float64, error)

func (*Container) GetFloat64Slice

func (g *Container) GetFloat64Slice(path ...string) ([]float64, error)

func (*Container) GetFloat64SliceP

func (g *Container) GetFloat64SliceP(path string) ([]float64, error)

func (*Container) GetInt

func (g *Container) GetInt(path ...string) (int, error)

func (*Container) GetInt16

func (g *Container) GetInt16(path ...string) (int16, error)

func (*Container) GetInt16P

func (g *Container) GetInt16P(path string) (int16, error)

func (*Container) GetInt16Slice

func (g *Container) GetInt16Slice(path ...string) ([]int16, error)

func (*Container) GetInt16SliceP

func (g *Container) GetInt16SliceP(path string) ([]int16, error)

func (*Container) GetInt32

func (g *Container) GetInt32(path ...string) (int32, error)

func (*Container) GetInt32P

func (g *Container) GetInt32P(path string) (int32, error)

func (*Container) GetInt32Slice

func (g *Container) GetInt32Slice(path ...string) ([]int32, error)

func (*Container) GetInt32SliceP

func (g *Container) GetInt32SliceP(path string) ([]int32, error)

func (*Container) GetInt64

func (g *Container) GetInt64(path ...string) (int64, error)

func (*Container) GetInt64P

func (g *Container) GetInt64P(path string) (int64, error)

func (*Container) GetInt64Slice

func (g *Container) GetInt64Slice(path ...string) ([]int64, error)

func (*Container) GetInt64SliceP

func (g *Container) GetInt64SliceP(path string) ([]int64, error)

func (*Container) GetInt8

func (g *Container) GetInt8(path ...string) (int8, error)

func (*Container) GetInt8P

func (g *Container) GetInt8P(path string) (int8, error)

func (*Container) GetInt8Slice

func (g *Container) GetInt8Slice(path ...string) ([]int8, error)

func (*Container) GetInt8SliceP

func (g *Container) GetInt8SliceP(path string) ([]int8, error)

func (*Container) GetIntP

func (g *Container) GetIntP(path string) (int, error)

func (*Container) GetIntSlice

func (g *Container) GetIntSlice(path ...string) ([]int, error)

func (*Container) GetIntSliceP

func (g *Container) GetIntSliceP(path string) ([]int, error)

func (*Container) GetString

func (g *Container) GetString(path ...string) (string, error)

func (*Container) GetStringP

func (g *Container) GetStringP(path string) (string, error)

func (*Container) GetStringSlice

func (g *Container) GetStringSlice(path ...string) ([]string, error)

func (*Container) GetStringSliceP

func (g *Container) GetStringSliceP(path string) ([]string, error)

func (*Container) GetUint

func (g *Container) GetUint(path ...string) (uint, error)

func (*Container) GetUint16

func (g *Container) GetUint16(path ...string) (uint16, error)

func (*Container) GetUint16P

func (g *Container) GetUint16P(path string) (uint16, error)

func (*Container) GetUint16Slice

func (g *Container) GetUint16Slice(path ...string) ([]uint16, error)

func (*Container) GetUint16SliceP

func (g *Container) GetUint16SliceP(path string) ([]uint16, error)

func (*Container) GetUint32

func (g *Container) GetUint32(path ...string) (uint32, error)

func (*Container) GetUint32P

func (g *Container) GetUint32P(path string) (uint32, error)

func (*Container) GetUint32Slice

func (g *Container) GetUint32Slice(path ...string) ([]uint32, error)

func (*Container) GetUint32SliceP

func (g *Container) GetUint32SliceP(path string) ([]uint32, error)

func (*Container) GetUint64

func (g *Container) GetUint64(path ...string) (uint64, error)

func (*Container) GetUint64P

func (g *Container) GetUint64P(path string) (uint64, error)

func (*Container) GetUint64Slice

func (g *Container) GetUint64Slice(path ...string) ([]uint64, error)

func (*Container) GetUint64SliceP

func (g *Container) GetUint64SliceP(path string) ([]uint64, error)

func (*Container) GetUint8

func (g *Container) GetUint8(path ...string) (uint8, error)

func (*Container) GetUint8P

func (g *Container) GetUint8P(path string) (uint8, error)

func (*Container) GetUint8Slice

func (g *Container) GetUint8Slice(path ...string) ([]uint8, error)

func (*Container) GetUint8SliceP

func (g *Container) GetUint8SliceP(path string) ([]uint8, error)

func (*Container) GetUintP

func (g *Container) GetUintP(path string) (uint, error)

func (*Container) GetUintSlice

func (g *Container) GetUintSlice(path ...string) ([]uint, error)

func (*Container) GetUintSliceP

func (g *Container) GetUintSliceP(path string) ([]uint, error)

func (*Container) Index

func (g *Container) Index(index int) *Container

Index - Attempt to find and return an object within a JSON array by index.

func (*Container) IsArray

func (g *Container) IsArray(path ...string) bool

</editor-fold>

func (*Container) IsMap

func (g *Container) IsMap(path ...string) bool

func (*Container) IsNil

func (g *Container) IsNil(path ...string) bool

func (*Container) Merge

func (g *Container) Merge(toMerge *Container) error

Merge - Merges two gabs-containers

func (*Container) MsgPackBytes

func (g *Container) MsgPackBytes() []byte

func (*Container) MustGetBool

func (g *Container) MustGetBool(path ...string) bool

func (*Container) MustGetBoolP

func (g *Container) MustGetBoolP(path string) bool

func (*Container) MustGetBoolSlice

func (g *Container) MustGetBoolSlice(path ...string) []bool

func (*Container) MustGetBoolSliceP

func (g *Container) MustGetBoolSliceP(path string) []bool

func (*Container) MustGetByteSlice

func (g *Container) MustGetByteSlice(path ...string) []byte

func (*Container) MustGetByteSliceP

func (g *Container) MustGetByteSliceP(path string) []byte

func (*Container) MustGetFloat32

func (g *Container) MustGetFloat32(path ...string) float32

func (*Container) MustGetFloat32P

func (g *Container) MustGetFloat32P(path string) float32

func (*Container) MustGetFloat32Slice

func (g *Container) MustGetFloat32Slice(path ...string) []float32

func (*Container) MustGetFloat32SliceP

func (g *Container) MustGetFloat32SliceP(path string) []float32

func (*Container) MustGetFloat64

func (g *Container) MustGetFloat64(path ...string) float64

func (*Container) MustGetFloat64P

func (g *Container) MustGetFloat64P(path string) float64

func (*Container) MustGetFloat64Slice

func (g *Container) MustGetFloat64Slice(path ...string) []float64

func (*Container) MustGetFloat64SliceP

func (g *Container) MustGetFloat64SliceP(path string) []float64

func (*Container) MustGetInt

func (g *Container) MustGetInt(path ...string) int

func (*Container) MustGetInt16

func (g *Container) MustGetInt16(path ...string) int16

func (*Container) MustGetInt16P

func (g *Container) MustGetInt16P(path string) int16

func (*Container) MustGetInt16Slice

func (g *Container) MustGetInt16Slice(path ...string) []int16

func (*Container) MustGetInt16SliceP

func (g *Container) MustGetInt16SliceP(path string) []int16

func (*Container) MustGetInt32

func (g *Container) MustGetInt32(path ...string) int32

func (*Container) MustGetInt32P

func (g *Container) MustGetInt32P(path string) int32

func (*Container) MustGetInt32Slice

func (g *Container) MustGetInt32Slice(path ...string) []int32

func (*Container) MustGetInt32SliceP

func (g *Container) MustGetInt32SliceP(path string) []int32

func (*Container) MustGetInt64

func (g *Container) MustGetInt64(path ...string) int64

func (*Container) MustGetInt64P

func (g *Container) MustGetInt64P(path string) int64

func (*Container) MustGetInt64Slice

func (g *Container) MustGetInt64Slice(path ...string) []int64

func (*Container) MustGetInt64SliceP

func (g *Container) MustGetInt64SliceP(path string) []int64

func (*Container) MustGetInt8

func (g *Container) MustGetInt8(path ...string) int8

func (*Container) MustGetInt8P

func (g *Container) MustGetInt8P(path string) int8

func (*Container) MustGetInt8Slice

func (g *Container) MustGetInt8Slice(path ...string) []int8

func (*Container) MustGetInt8SliceP

func (g *Container) MustGetInt8SliceP(path string) []int8

func (*Container) MustGetIntP

func (g *Container) MustGetIntP(path string) int

func (*Container) MustGetIntSlice

func (g *Container) MustGetIntSlice(path ...string) []int

func (*Container) MustGetIntSliceP

func (g *Container) MustGetIntSliceP(path string) []int

func (*Container) MustGetString

func (g *Container) MustGetString(path ...string) string

func (*Container) MustGetStringP

func (g *Container) MustGetStringP(path string) string

func (*Container) MustGetStringSlice

func (g *Container) MustGetStringSlice(path ...string) []string

func (*Container) MustGetStringSliceP

func (g *Container) MustGetStringSliceP(path string) []string

func (*Container) MustGetUint

func (g *Container) MustGetUint(path ...string) uint

func (*Container) MustGetUint16

func (g *Container) MustGetUint16(path ...string) uint16

func (*Container) MustGetUint16P

func (g *Container) MustGetUint16P(path string) uint16

func (*Container) MustGetUint16Slice

func (g *Container) MustGetUint16Slice(path ...string) []uint16

func (*Container) MustGetUint16SliceP

func (g *Container) MustGetUint16SliceP(path string) []uint16

func (*Container) MustGetUint32

func (g *Container) MustGetUint32(path ...string) uint32

func (*Container) MustGetUint32P

func (g *Container) MustGetUint32P(path string) uint32

func (*Container) MustGetUint32Slice

func (g *Container) MustGetUint32Slice(path ...string) []uint32

func (*Container) MustGetUint32SliceP

func (g *Container) MustGetUint32SliceP(path string) []uint32

func (*Container) MustGetUint64

func (g *Container) MustGetUint64(path ...string) uint64

func (*Container) MustGetUint64P

func (g *Container) MustGetUint64P(path string) uint64

func (*Container) MustGetUint64Slice

func (g *Container) MustGetUint64Slice(path ...string) []uint64

func (*Container) MustGetUint64SliceP

func (g *Container) MustGetUint64SliceP(path string) []uint64

func (*Container) MustGetUint8

func (g *Container) MustGetUint8(path ...string) uint8

func (*Container) MustGetUint8P

func (g *Container) MustGetUint8P(path string) uint8

func (*Container) MustGetUint8Slice

func (g *Container) MustGetUint8Slice(path ...string) []uint8

func (*Container) MustGetUint8SliceP

func (g *Container) MustGetUint8SliceP(path string) []uint8

func (*Container) MustGetUintP

func (g *Container) MustGetUintP(path string) uint

func (*Container) MustGetUintSlice

func (g *Container) MustGetUintSlice(path ...string) []uint

func (*Container) MustGetUintSliceP

func (g *Container) MustGetUintSliceP(path string) []uint

func (*Container) Object

func (g *Container) Object(path ...string) (*Container, error)

Object - Create a new JSON object at a path. Returns an error if the path contains a collision with a non object type.

func (*Container) ObjectI

func (g *Container) ObjectI(index int) (*Container, error)

ObjectI - Create a new JSON object at an array index. Returns an error if the object is not an array or the index is out of bounds.

func (*Container) ObjectP

func (g *Container) ObjectP(path string) (*Container, error)

ObjectP - Does the same as Object, but using a dot notation JSON path.

func (*Container) Path

func (g *Container) Path(path string) *Container

Path - Search for a value using dot notation.

func (*Container) ReflectType

func (g *Container) ReflectType(path ...string) string

func (*Container) S

func (g *Container) S(hierarchy ...string) *Container

S - Shorthand method, does the same thing as Search.

func (*Container) Search

func (g *Container) Search(hierarchy ...string) *Container

Search - Attempt to find and return an object within the JSON structure by specifying the hierarchy of field names to locate the target. If the search encounters an array and has not reached the end target then it will iterate each object of the array for the target and return all of the results in a JSON array.

func (*Container) Set

func (g *Container) Set(value interface{}, path ...string) (*Container, error)

Set - Set the value of a field at a JSON path, any parts of the path that do not exist will be constructed, and if a collision occurs with a non object type whilst iterating the path an error is returned.

func (*Container) SetIndex

func (g *Container) SetIndex(value interface{}, index int) (*Container, error)

SetIndex - Set a value of an array element based on the index.

func (*Container) SetP

func (g *Container) SetP(value interface{}, path string) (*Container, error)

SetP - Does the same as Set, but using a dot notation JSON path.

func (*Container) String

func (g *Container) String() string

String - Converts the contained object to a JSON formatted string.

func (*Container) StringIndent

func (g *Container) StringIndent(prefix string, indent string) string

StringIndent - Converts the contained object back to a JSON formatted string with prefix, indent.

type EncodeOpt

type EncodeOpt func(e *json.Encoder)

EncodeOpt is a functional option for the EncodeJSON method.

func EncodeOptHTMLEscape

func EncodeOptHTMLEscape(doEscape bool) EncodeOpt

EncodeOptHTMLEscape sets the encoder to escape the JSON for html.

func EncodeOptIndent

func EncodeOptIndent(prefix string, indent string) EncodeOpt

EncodeOptIndent sets the encoder to indent the JSON output.

Jump to

Keyboard shortcuts

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