jsonmap

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

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

Go to latest
Published: May 24, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JsonMap

type JsonMap map[string]interface{}

func NewJsonMapFromIoReader

func NewJsonMapFromIoReader(jsonReader io.Reader) (JsonMap, error)

NewJsonMapFromIoReader creates a JsonMap from an io.Reader. It returns an error if valid JSON cannot be decoded from the io.Reader. Note: This function expects the top-level JSON object to be a map and will fail if it is a slice (use NewJsonSliceFromIoReader for a top-level slice).

func NewJsonMapFromJsonBytes

func NewJsonMapFromJsonBytes(jsonBytes []byte) (JsonMap, error)

NewJsonMapFromJsonBytes creates a JsonMap from a byte slice. It returns an error if valid JSON cannot be decoded from the bytes. Note: This function expects the top-level JSON object to be a map and will fail if it is a slice (use NewJsonSliceFromJsonBytes for a top-level slice).

func NewJsonMapFromJsonString

func NewJsonMapFromJsonString(jsonString string) (JsonMap, error)

NewJsonMapFromJsonString creates a JsonMap from a string. It returns an error if valid JSON cannot be decoded from the string. Note: This function expects the top-level JSON object to be a map and will fail if it is a slice (use NewJsonSliceFromJsonString for a top-level slice).

func (*JsonMap) GetBool

func (m *JsonMap) GetBool(key string) (bool, error)

GetBool retrieves, from the map, a bool with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a bool.

func (*JsonMap) GetBoolAtPath

func (m *JsonMap) GetBoolAtPath(path string) (bool, error)

GetBoolAtPath retrieves, from the map, a bool at the specified path. It will return an error if the path is invalid or if the value at the path is not a bool. Note that map paths should always begin with a key. e.g. "keyForMap.keyForBool" (map with a map with a bool value) or "keyForBoolSlice[0]" (map with a slice of bool values) or "keyForMap.keyForBoolSlice[0]" (map with a map with a slice of bool values)

func (*JsonMap) GetBoolAtPathWithDefault

func (m *JsonMap) GetBoolAtPathWithDefault(path string, defaultValue bool) (bool, error)

GetBoolAtPathWithDefault retrieves, from the map, a bool at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a bool. Note that map paths should always begin with a key. e.g. "keyForMap.keyForBool" (map with a map with a bool value) or "keyForBoolSlice[0]" (map with a slice of bool values) or "keyForMap.keyForBoolSlice[0]" (map with a map with a slice of bool values)

func (*JsonMap) GetBoolWithDefault

func (m *JsonMap) GetBoolWithDefault(key string, defaultValue bool) (bool, error)

GetBoolWithDefault retrieves, from the map, a bool with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a bool.

func (*JsonMap) GetFloat

func (m *JsonMap) GetFloat(key string) (float64, error)

GetFloat retrieves, from the map, a float with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a float (if the value at the index is an integer, it will be quietly converted to a float).

func (*JsonMap) GetFloatAtPath

func (m *JsonMap) GetFloatAtPath(path string) (float64, error)

GetFloatAtPath retrieves, from the map, a float at the specified path. It will return an error if the path is invalid or if the value at the path is not a float (if the value at the index is an int, it will be quietly converted to a float). Note that map paths should always begin with a key. e.g. "keyForMap.keyForFloat" (map with a map with a float value) or "keyForFloatSlice[0]" (map with a slice of float values) or "keyForMap.keyForFloatSlice[0]" (map with a map with a slice of float values)

func (*JsonMap) GetFloatAtPathWithDefault

func (m *JsonMap) GetFloatAtPathWithDefault(path string, defaultValue float64) (float64, error)

GetFloatAtPathWithDefault retrieves, from the map, a float at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a float (if the value at the index is an int, it will be quietly converted to a float). Note that map paths should always begin with a key. e.g. "keyForMap.keyForFloat" (map with a map with a float value) or "keyForFloatSlice[0]" (map with a slice of float values) or "keyForMap.keyForFloatSlice[0]" (map with a map with a slice of float values)

func (*JsonMap) GetFloatWithDefault

func (m *JsonMap) GetFloatWithDefault(key string, defaultValue float64) (float64, error)

GetFloatWithDefault retrieves, from the map, a float with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a float (if the value at the index is an integer, it will be quietly converted to a float).

func (*JsonMap) GetInt

func (m *JsonMap) GetInt(key string) (int64, error)

GetInt retrieves, from the map, an int with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not an int.

func (*JsonMap) GetIntAtPath

func (m *JsonMap) GetIntAtPath(path string) (int64, error)

GetIntAtPath retrieves, from the map, an int at the specified path. It will return an error if the path is invalid or if the value at the path is not an int. Note that map paths should always begin with a key. e.g. "keyForMap.keyForInt" (map with a map with an int value) or "keyForIntSlice[0]" (map with a slice of int values) or "keyForMap.keyForIntSlice[0]" (map with a map with a slice of int values)

func (*JsonMap) GetIntAtPathWithDefault

func (m *JsonMap) GetIntAtPathWithDefault(path string, defaultValue int64) (int64, error)

GetIntAtPathWithDefault retrieves, from the map, an int at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not an int. Note that map paths should always begin with a key. e.g. "keyForMap.keyForInt" (map with a map with an int value) or "keyForIntSlice[0]" (map with a slice of int values) or "keyForMap.keyForIntSlice[0]" (map with a map with a slice of int values)

func (*JsonMap) GetIntWithDefault

func (m *JsonMap) GetIntWithDefault(key string, defaultValue int64) (int64, error)

GetIntWithDefault retrieves, from the map, an int with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not an int.

func (*JsonMap) GetMap

func (m *JsonMap) GetMap(key string) (JsonMap, error)

GetMap retrieves, from the map, a JsonMap with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonMap.

func (*JsonMap) GetMapAtPath

func (m *JsonMap) GetMapAtPath(path string) (JsonMap, error)

GetMapAtPath retrieves, from the map, a JsonMap at the specified path. It will return an error if the path is invalid or if the value at the path is not a JsonMap. Note that map paths should always begin with a key. e.g. "keyForMap.keyForMap" (map with a map with a map value) or "keyForMapSlice[0]" (map with a slice of map values) or "keyForMap.keyForMapSlice[0]" (map with a map with a slice of map values)

func (*JsonMap) GetMapAtPathWithDefault

func (m *JsonMap) GetMapAtPathWithDefault(path string, defaultValue JsonMap) (JsonMap, error)

GetMapAtPathWithDefault retrieves, from the map, a JsonMap at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonMap. Note that map paths should always begin with a key. e.g. "keyForMap.keyForMap" (map with a map with a map value) or "keyForMapSlice[0]" (map with a slice of map values) or "keyForMap.keyForMapSlice[0]" (map with a map with a slice of map values)

func (*JsonMap) GetMapWithDefault

func (m *JsonMap) GetMapWithDefault(key string, defaultValue JsonMap) (JsonMap, error)

GetMapWithDefault retrieves, from the map, a JsonMap with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonMap.

func (*JsonMap) GetSlice

func (m *JsonMap) GetSlice(key string) (JsonSlice, error)

GetSlice retrieves, from the map, a JsonSlice with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice.

func (*JsonMap) GetSliceAtPath

func (m *JsonMap) GetSliceAtPath(path string) (JsonSlice, error)

GetSliceAtPath retrieves, from the map, a JsonSlice at the specified path. It will return an error if the path is invalid or if the value at the path is not a JsonSlice. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceAtPathWithDefault

func (m *JsonMap) GetSliceAtPathWithDefault(path string, defaultValue JsonSlice) (JsonSlice, error)

GetSliceAtPathWithDefault retrieves, from the map, a JsonSlice at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfBools

func (m *JsonMap) GetSliceOfBools(key string) ([]bool, error)

GetSliceOfBools retrieves, from the map, a []bool64 with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a bool.

func (*JsonMap) GetSliceOfBoolsAtPath

func (m *JsonMap) GetSliceOfBoolsAtPath(path string) ([]bool, error)

GetSliceOfBoolsAtPath retrieves, from the map, a []bool at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a bool. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfBoolsAtPathWithDefault

func (m *JsonMap) GetSliceOfBoolsAtPathWithDefault(path string, defaultValue []bool) ([]bool, error)

GetSliceOfBoolsAtPathWithDefault retrieves, from the map, a []bool at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a bool. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfBoolsWithDefault

func (m *JsonMap) GetSliceOfBoolsWithDefault(key string, defaultValue []bool) ([]bool, error)

GetSliceOfBoolsWithDefault retrieves, from the map, a []bool64 with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a bool.

func (*JsonMap) GetSliceOfFloats

func (m *JsonMap) GetSliceOfFloats(key string) ([]float64, error)

GetSliceOfFloats retrieves, from the map, a []float64 with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a float.

func (*JsonMap) GetSliceOfFloatsAtPath

func (m *JsonMap) GetSliceOfFloatsAtPath(path string) ([]float64, error)

GetSliceOfFloatsAtPath retrieves, from the map, a []float64 at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a float. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfFloatsAtPathWithDefault

func (m *JsonMap) GetSliceOfFloatsAtPathWithDefault(path string, defaultValue []float64) ([]float64, error)

GetSliceOfFloatsAtPathWithDefault retrieves, from the map, a []float64 at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a float. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfFloatsWithDefault

func (m *JsonMap) GetSliceOfFloatsWithDefault(key string, defaultValue []float64) ([]float64, error)

GetSliceOfFloatsWithDefault retrieves, from the map, a []float64 with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a float.

func (*JsonMap) GetSliceOfInts

func (m *JsonMap) GetSliceOfInts(key string) ([]int64, error)

GetSliceOfInts retrieves, from the map, a []int64 with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not an int.

func (*JsonMap) GetSliceOfIntsAtPath

func (m *JsonMap) GetSliceOfIntsAtPath(path string) ([]int64, error)

GetSliceOfIntsAtPath retrieves, from the map, a []int64 at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not an int. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfIntsAtPathWithDefault

func (m *JsonMap) GetSliceOfIntsAtPathWithDefault(path string, defaultValue []int64) ([]int64, error)

GetSliceOfIntsAtPathWithDefault retrieves, from the map, a []int64 at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not an int. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfIntsWithDefault

func (m *JsonMap) GetSliceOfIntsWithDefault(key string, defaultValue []int64) ([]int64, error)

GetSliceOfIntsWithDefault retrieves, from the map, a []int64 with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not an int.

func (*JsonMap) GetSliceOfMaps

func (m *JsonMap) GetSliceOfMaps(key string) ([]JsonMap, error)

GetSliceOfMaps retrieves, from the map, a []JsonMap with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a JsonMap.

func (*JsonMap) GetSliceOfMapsAtPath

func (m *JsonMap) GetSliceOfMapsAtPath(path string) ([]JsonMap, error)

GetSliceOfMapsAtPath retrieves, from the map, a []JsonMap at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a JsonMap. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfMapsAtPathWithDefault

func (m *JsonMap) GetSliceOfMapsAtPathWithDefault(path string, defaultValue []JsonMap) ([]JsonMap, error)

GetSliceOfMapsAtPathWithDefault retrieves, from the map, a []JsonMap at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a JsonMap. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfMapsWithDefault

func (m *JsonMap) GetSliceOfMapsWithDefault(key string, defaultValue []JsonMap) ([]JsonMap, error)

GetSliceOfMapsWithDefault retrieves, from the map, a []JsonMap with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a JsonMap.

func (*JsonMap) GetSliceOfSlices

func (m *JsonMap) GetSliceOfSlices(key string) ([]JsonSlice, error)

GetSliceOfSlices retrieves, from the map, a []JsonSlice with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a JsonSlice.

func (*JsonMap) GetSliceOfSlicesAtPath

func (m *JsonMap) GetSliceOfSlicesAtPath(path string) ([]JsonSlice, error)

GetSliceOfSlicesAtPath retrieves, from the map, a []JsonSlice at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a JsonSlice. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfSlicesAtPathWithDefault

func (m *JsonMap) GetSliceOfSlicesAtPathWithDefault(path string, defaultValue []JsonSlice) ([]JsonSlice, error)

GetSliceOfSlicesAtPathWithDefault retrieves, from the map, a []JsonSlice at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a JsonSlice. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfSlicesWithDefault

func (m *JsonMap) GetSliceOfSlicesWithDefault(key string, defaultValue []JsonSlice) ([]JsonSlice, error)

GetSliceOfSlicesWithDefault retrieves, from the map, a []JsonSlice with the specified key. If the key can not be found in the map (including an invalid, empty key, ""), then it returns the default value. It will return an error if the value at the index is not a JsonSlice or if any value in the slice is not a JsonSlice.

func (*JsonMap) GetSliceOfStrings

func (m *JsonMap) GetSliceOfStrings(key string) ([]string, error)

GetSliceOfStrings retrieves, from the map, a []string with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a string.

func (*JsonMap) GetSliceOfStringsAtPath

func (m *JsonMap) GetSliceOfStringsAtPath(path string) ([]string, error)

GetSliceOfStringsAtPath retrieves, from the map, a []string at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a string. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfStringsAtPathWithDefault

func (m *JsonMap) GetSliceOfStringsAtPathWithDefault(path string, defaultValue []string) ([]string, error)

GetSliceOfStringsAtPathWithDefault retrieves, from the map, a []string at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a string. Note that map paths should always begin with a key. e.g. "keyForMap.keyForSlice" (map with a map with a slice value) or "keyForSliceSlice[0]" (map with a slice of slice values) or "keyForMap.keyForSliceSlice[0]" (map with a map with a slice of slice values)

func (*JsonMap) GetSliceOfStringsWithDefault

func (m *JsonMap) GetSliceOfStringsWithDefault(key string, defaultValue []string) ([]string, error)

GetSliceOfStringsWithDefault retrieves, from the map, a []string with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice or if any value in the slice is not a string.

func (*JsonMap) GetSliceWithDefault

func (m *JsonMap) GetSliceWithDefault(key string, defaultValue JsonSlice) (JsonSlice, error)

GetSliceWithDefault retrieves, from the map, a JsonSlice with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a JsonSlice.

func (*JsonMap) GetString

func (m *JsonMap) GetString(key string) (string, error)

GetString retrieves, from the map, a string with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a string.

func (*JsonMap) GetStringAtPath

func (m *JsonMap) GetStringAtPath(path string) (string, error)

GetStringAtPath retrieves, from the map, a string at the specified path. It will return an error if the path is invalid or if the value at the path is not a string. Note that map paths should always begin with a key. e.g. "keyForMap.keyForString" (map with a map with a string value) or "keyForStringSlice[0]" (map with a slice of string values) or "keyForMap.keyForStringSlice[0]" (map with a map with a slice of string values)

func (*JsonMap) GetStringAtPathWithDefault

func (m *JsonMap) GetStringAtPathWithDefault(path string, defaultValue string) (string, error)

GetStringAtPathWithDefault retrieves, from the map, a string at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a string. Note that map paths should always begin with a key. e.g. "keyForMap.keyForString" (map with a map with a string value) or "keyForStringSlice[0]" (map with a slice of string values) or "keyForMap.keyForStringSlice[0]" (map with a map with a slice of string values)

func (*JsonMap) GetStringWithDefault

func (m *JsonMap) GetStringWithDefault(key string, defaultValue string) (string, error)

GetStringWithDefault retrieves, from the map, a string with the specified key. It will return an error if the key does not exist in the map or if the value at the index is not a string.

func (*JsonMap) GetValue

func (m *JsonMap) GetValue(key string) (interface{}, error)

GetValue retrieves, from the map, an object of any type with the specified key. It will return an error if the key does not exist in the map.

func (*JsonMap) GetValueAtPath

func (m *JsonMap) GetValueAtPath(path string) (interface{}, error)

GetValueAtPath retrieves, from the map, an object of any type at the specified path. It will return an error if the path is invalid. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) GetValueAtPathWithDefault

func (m *JsonMap) GetValueAtPathWithDefault(path string, defaultValue interface{}) interface{}

GetValueAtPathWithDefault retrieves, from the map, an object of any type at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) GetValueWithDefault

func (m *JsonMap) GetValueWithDefault(key string, defaultValue interface{}) interface{}

GetValueWithDefault retrieves, from the map, an object of any type with the specified key. If the key can not be found in the map (including an invalid, empty key, ""), then it returns the default value.

func (*JsonMap) Map

func (m *JsonMap) Map(mapMapFn MapMapFn, sliceMapFn SliceMapFn) JsonMap

Map recursively applies mapping functions to a map and returns the new, transformed map. See MapMapFn and SliceMapFn for explanations of the mapping function parameters. Either or both may be nil, but note that maps may contain slices, which is why JsonMap.Map() allows you to specify mapping functions for both maps and slices.

func (*JsonMap) SetBool

func (m *JsonMap) SetBool(key string, value bool)

SetBool sets a bool with the specified key in the map.

func (*JsonMap) SetBoolAtPath

func (m *JsonMap) SetBoolAtPath(path string, value bool) error

SetBoolAtPath sets a bool value in the map at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) SetFloat

func (m *JsonMap) SetFloat(key string, value float64)

SetFloat sets a float with the specified key in the map.

func (*JsonMap) SetFloatAtPath

func (m *JsonMap) SetFloatAtPath(path string, value float64) error

SetFloatAtPath sets a float value in the map at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) SetInt

func (m *JsonMap) SetInt(key string, value int64)

SetInt sets an int with the specified key in the map.

func (*JsonMap) SetIntAtPath

func (m *JsonMap) SetIntAtPath(path string, value int64) error

SetIntAtPath sets an int value in the map at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) SetMap

func (m *JsonMap) SetMap(key string, value JsonMap)

SetMap sets a map with the specified key in the map. Use caution with this method. If you add a map that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the map.

func (*JsonMap) SetMapAtPath

func (m *JsonMap) SetMapAtPath(path string, value JsonMap) error

SetMapAtPath sets a JsonMap value in the map at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Use caution with this method. If you add a map that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the map. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) SetSlice

func (m *JsonMap) SetSlice(key string, value JsonSlice)

SetSlice sets a slice with the specified key in the map. It will only return an error if an empty key is provided. Use caution with this method. If you add a slice that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the map.

func (*JsonMap) SetSliceAtPath

func (m *JsonMap) SetSliceAtPath(path string, value JsonSlice) error

SetSliceAtPath sets a JsonSlice value in the map at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Use caution with this method. If you add a slice that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the map. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) SetString

func (m *JsonMap) SetString(key string, value string)

SetString sets a string with the specified key in the map.

func (*JsonMap) SetStringAtPath

func (m *JsonMap) SetStringAtPath(path string, value string) error

SetStringAtPath sets a string value in the map at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) SetValue

func (m *JsonMap) SetValue(key string, value interface{})

SetValue sets an object of any type with the specified key in the map. Use caution with this method. If you add an object that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the map.

func (*JsonMap) SetValueAtPath

func (m *JsonMap) SetValueAtPath(path string, value interface{}) error

SetValueAtPath sets an object of any type in the map at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Use caution with this method. If you add an object that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the map. Note that map paths should always begin with a key. e.g. "keyForMap.keyForValue" (map with a map with a value) or "keyForValueSlice[0]" (map with a slice of values) or "keyForMap.keyForValueSlice[0]" (map with a map with a slice of values)

func (*JsonMap) ToIoWriter

func (m *JsonMap) ToIoWriter(jsonWriter io.Writer, pretty bool, escapeHtml bool) error

func (*JsonMap) ToJsonBytes

func (m *JsonMap) ToJsonBytes(pretty bool, escapeHtml bool) ([]byte, error)

func (*JsonMap) ToJsonString

func (m *JsonMap) ToJsonString(pretty bool, escapeHtml bool) (string, error)

type JsonSlice

type JsonSlice []interface{}

func NewJsonSliceFromIoReader

func NewJsonSliceFromIoReader(jsonReader io.Reader) (JsonSlice, error)

NewJsonSliceFromIoReader creates a JsonSlice from an io.Reader. It returns an error if valid JSON cannot be decoded from the io.Reader. Note: This function expects the top-level JSON object to be a slice and will fail if it is a map (use NewJsonMapFromIoReader for a top-level map).

func NewJsonSliceFromJsonBytes

func NewJsonSliceFromJsonBytes(jsonBytes []byte) (JsonSlice, error)

NewJsonSliceFromJsonBytes creates a JsonSlice from an io.Reader. It returns an error if valid JSON cannot be decoded from the io.Reader. Note: This function expects the top-level JSON object to be a slice and will fail if it is a map (use NewJsonMapFromJsonBytes for a top-level map).

func NewJsonSliceFromJsonString

func NewJsonSliceFromJsonString(jsonString string) (JsonSlice, error)

NewJsonSliceFromJsonString creates a JsonSlice from an io.Reader. It returns an error if valid JSON cannot be decoded from the io.Reader. Note: This function expects the top-level JSON object to be a slice and will fail if it is a map (use NewJsonMapFromJsonString for a top-level map).

func NewJsonSliceFromSlice

func NewJsonSliceFromSlice[T any](s []T) JsonSlice

NewJsonSliceFromSlice creates a JsonSlice from a slice of any type

func (*JsonSlice) GetBool

func (s *JsonSlice) GetBool(index int) (bool, error)

GetBool retrieves, from the slice, a bool at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a bool.

func (*JsonSlice) GetBoolAtPath

func (s *JsonSlice) GetBoolAtPath(path string) (bool, error)

GetBoolAtPath retrieves, from the slice, a bool at the specified path. It will return an error if the path is invalid or if the value at the path is not a bool. Note that slice paths should always begin with an array index. e.g. "[0].keyForBool" (slice of maps with bool value) or "[0][0]" (slice of slices of bool values)

func (*JsonSlice) GetBoolAtPathWithDefault

func (s *JsonSlice) GetBoolAtPathWithDefault(path string, defaultValue bool) (bool, error)

GetBoolAtPathWithDefault retrieves, from the slice, a bool at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a bool. Note that slice paths should always begin with an array index. e.g. "[0].keyForBool" (slice of maps with bool value) or "[0][0]" (slice of slices of bool values)

func (*JsonSlice) GetBoolWithDefault

func (s *JsonSlice) GetBoolWithDefault(index int, defaultValue bool) (bool, error)

GetBoolWithDefault retrieves, from the slice, a bool at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a bool.

func (*JsonSlice) GetFloat

func (s *JsonSlice) GetFloat(index int) (float64, error)

GetFloat retrieves, from the slice, a float at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a float (if the value at the index is an int, it will be quietly converted to a float).

func (*JsonSlice) GetFloatAtPath

func (s *JsonSlice) GetFloatAtPath(path string) (float64, error)

GetFloatAtPath retrieves, from the slice, a float at the specified path. It will return an error if the path is invalid or if the value at the path is not a float (if the value at the index is an int, it will be quietly converted to a float). Note that slice paths should always begin with an array index. e.g. "[0].keyForFloat" (slice of maps with float value) or "[0][0]" (slice of slices of float values)

func (*JsonSlice) GetFloatAtPathWithDefault

func (s *JsonSlice) GetFloatAtPathWithDefault(path string, defaultValue float64) (float64, error)

GetFloatAtPathWithDefault retrieves, from the slice, a float at the specified path. It will return an error if the value at the path is not a float (if the value at the index is an int, it will be quietly converted to a float). Note that slice paths should always begin with an array index. e.g. "[0].keyForFloat" (slice of maps with float value) or "[0][0]" (slice of slices of float values)

func (*JsonSlice) GetFloatWithDefault

func (s *JsonSlice) GetFloatWithDefault(index int, defaultValue float64) (float64, error)

GetFloatWithDefault retrieves, from the slice, a float at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a float (if the value at the index is an int, it will be quietly converted to a float).

func (*JsonSlice) GetInt

func (s *JsonSlice) GetInt(index int) (int64, error)

GetInt retrieves, from the slice, an int at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not an int.

func (*JsonSlice) GetIntAtPath

func (s *JsonSlice) GetIntAtPath(path string) (int64, error)

GetIntAtPath retrieves, from the slice, an int at the specified path. It will return an error if the path is invalid or if the value at the path is not an int. Note that slice paths should always begin with an array index. e.g. "[0].keyForInt" (slice of maps with int value) or "[0][0]" (slice of slices of int values)

func (*JsonSlice) GetIntAtPathWithDefault

func (s *JsonSlice) GetIntAtPathWithDefault(path string, defaultValue int64) (int64, error)

GetIntAtPathWithDefault retrieves, from the slice, an int at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not an int. Note that slice paths should always begin with an array index. e.g. "[0].keyForInt" (slice of maps with int value) or "[0][0]" (slice of slices of int values)

func (*JsonSlice) GetIntWithDefault

func (s *JsonSlice) GetIntWithDefault(index int, defaultValue int64) (int64, error)

GetIntWithDefault retrieves, from the slice, an int at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not an int.

func (*JsonSlice) GetMap

func (s *JsonSlice) GetMap(index int) (JsonMap, error)

GetMap retrieves, from the slice, a JsonMap at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonMap.

func (*JsonSlice) GetMapAtPath

func (s *JsonSlice) GetMapAtPath(path string) (JsonMap, error)

GetMapAtPath retrieves, from the slice, a JsonMap at the specified path. It will return an error if the path is invalid or if the value at the path is not a JsonMap. Note that slice paths should always begin with an array index. e.g. "[0].keyForMap" (slice of maps with map value) or "[0][0]" (slice of slices of map values)

func (*JsonSlice) GetMapAtPathWithDefault

func (s *JsonSlice) GetMapAtPathWithDefault(path string, defaultValue JsonMap) (JsonMap, error)

GetMapAtPathWithDefault retrieves, from the slice, a JsonMap at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonMap. Note that slice paths should always begin with an array index. e.g. "[0].keyForMap" (slice of maps with map value) or "[0][0]" (slice of slices of map values)

func (*JsonSlice) GetMapWithDefault

func (s *JsonSlice) GetMapWithDefault(index int, defaultValue JsonMap) (JsonMap, error)

GetMapWithDefault retrieves, from the slice, a JsonMap at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonMap.

func (*JsonSlice) GetSlice

func (s *JsonSlice) GetSlice(index int) (JsonSlice, error)

GetSlice retrieves, from the slice, a JsonSlice at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice.

func (*JsonSlice) GetSliceAtPath

func (s *JsonSlice) GetSliceAtPath(path string) (JsonSlice, error)

GetSliceAtPath retrieves, from the slice, a JsonSlice at the specified path. It will return an error if the path is invalid or if the value at the path is not a JsonSlice. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceAtPathWithDefault

func (s *JsonSlice) GetSliceAtPathWithDefault(path string, defaultValue JsonSlice) (JsonSlice, error)

GetSliceAtPathWithDefault retrieves, from the slice, a JsonSlice at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfBools

func (s *JsonSlice) GetSliceOfBools(index int) ([]bool, error)

GetSliceOfBools retrieves, from the slice, a []bool at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a bool.

func (*JsonSlice) GetSliceOfBoolsAtPath

func (s *JsonSlice) GetSliceOfBoolsAtPath(path string) ([]bool, error)

GetSliceOfBoolsAtPath retrieves, from the slice, a []bool at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a bool. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfBoolsAtPathWithDefault

func (s *JsonSlice) GetSliceOfBoolsAtPathWithDefault(path string, defaultValue []bool) ([]bool, error)

GetSliceOfBoolsAtPathWithDefault retrieves, from the slice, a []bool at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a bool. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfBoolsWithDefault

func (s *JsonSlice) GetSliceOfBoolsWithDefault(index int, defaultValue []bool) ([]bool, error)

GetSliceOfBoolsWithDefault retrieves, from the slice, a []bool at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a bool.

func (*JsonSlice) GetSliceOfFloats

func (s *JsonSlice) GetSliceOfFloats(index int) ([]float64, error)

GetSliceOfFloats retrieves, from the slice, a []float64 at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a float64 (or an int64, which will be quietly converted to a float64).

func (*JsonSlice) GetSliceOfFloatsAtPath

func (s *JsonSlice) GetSliceOfFloatsAtPath(path string) ([]float64, error)

GetSliceOfFloatsAtPath retrieves, from the slice, a []float64 at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a float. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfFloatsAtPathWithDefault

func (s *JsonSlice) GetSliceOfFloatsAtPathWithDefault(path string, defaultValue []float64) ([]float64, error)

GetSliceOfFloatsAtPathWithDefault retrieves, from the slice, a []float64 at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a float. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfFloatsWithDefault

func (s *JsonSlice) GetSliceOfFloatsWithDefault(index int, defaultValue []float64) ([]float64, error)

GetSliceOfFloatsWithDefault retrieves, from the slice, a []float64 at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a float64 (or an int64, which will be quietly converted to a float64).

func (*JsonSlice) GetSliceOfInts

func (s *JsonSlice) GetSliceOfInts(index int) ([]int64, error)

GetSliceOfInts retrieves, from the slice, a []int64 at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not an int64.

func (*JsonSlice) GetSliceOfIntsAtPath

func (s *JsonSlice) GetSliceOfIntsAtPath(path string) ([]int64, error)

GetSliceOfIntsAtPath retrieves, from the slice, a []int64 at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not an int. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfIntsAtPathWithDefault

func (s *JsonSlice) GetSliceOfIntsAtPathWithDefault(path string, defaultValue []int64) ([]int64, error)

GetSliceOfIntsAtPathWithDefault retrieves, from the slice, a []int64 at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not an int. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfIntsWithDefault

func (s *JsonSlice) GetSliceOfIntsWithDefault(index int, defaultValue []int64) ([]int64, error)

GetSliceOfIntsWithDefault retrieves, from the slice, a []int64 at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not an int64.

func (*JsonSlice) GetSliceOfMaps

func (s *JsonSlice) GetSliceOfMaps(index int) ([]JsonMap, error)

GetSliceOfMaps retrieves, from the slice, a []JsonMap at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a JsonMap.

func (*JsonSlice) GetSliceOfMapsAtPath

func (s *JsonSlice) GetSliceOfMapsAtPath(path string) ([]JsonMap, error)

GetSliceOfMapsAtPath retrieves, from the slice, a []JsonMap at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a map. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfMapsAtPathWithDefault

func (s *JsonSlice) GetSliceOfMapsAtPathWithDefault(path string, defaultValue []JsonMap) ([]JsonMap, error)

GetSliceOfMapsAtPathWithDefault retrieves, from the slice, a []JsonMap at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a map. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfMapsWithDefault

func (s *JsonSlice) GetSliceOfMapsWithDefault(index int, defaultValue []JsonMap) ([]JsonMap, error)

GetSliceOfMapsWithDefault retrieves, from the slice, a []JsonMap at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a JsonMap.

func (*JsonSlice) GetSliceOfSlices

func (s *JsonSlice) GetSliceOfSlices(index int) ([]JsonSlice, error)

GetSliceOfSlices retrieves, from the slice, a []JsonSlice at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a JsonSlice.

func (*JsonSlice) GetSliceOfSlicesAtPath

func (s *JsonSlice) GetSliceOfSlicesAtPath(path string) ([]JsonSlice, error)

GetSliceOfSlicesAtPath retrieves, from the slice, a []JsonSlice at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a slice. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfSlicesAtPathWithDefault

func (s *JsonSlice) GetSliceOfSlicesAtPathWithDefault(path string, defaultValue []JsonSlice) ([]JsonSlice, error)

GetSliceOfSlicesAtPathWithDefault retrieves, from the slice, a []JsonSlice at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a slice. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfSlicesWithDefault

func (s *JsonSlice) GetSliceOfSlicesWithDefault(index int, defaultValue []JsonSlice) ([]JsonSlice, error)

GetSliceOfSlicesWithDefault retrieves, from the slice, a []JsonSlice at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a JsonSlice.

func (*JsonSlice) GetSliceOfStrings

func (s *JsonSlice) GetSliceOfStrings(index int) ([]string, error)

GetSliceOfStrings retrieves, from the slice, a []string at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a string.

func (*JsonSlice) GetSliceOfStringsAtPath

func (s *JsonSlice) GetSliceOfStringsAtPath(path string) ([]string, error)

GetSliceOfStringsAtPath retrieves, from the slice, a []string at the specified path. It will return an error if the path is invalid, if the value at the path is not a JsonSlice, or if any value in the slice is not a string. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfStringsAtPathWithDefault

func (s *JsonSlice) GetSliceOfStringsAtPathWithDefault(path string, defaultValue []string) ([]string, error)

GetSliceOfStringsAtPathWithDefault retrieves, from the slice, a []string at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a JsonSlice or if any value in the slice is not a string. Note that slice paths should always begin with an array index. e.g. "[0].keyForSlice" (slice of maps with slice value) or "[0][0]" (slice of slices of slice values)

func (*JsonSlice) GetSliceOfStringsWithDefault

func (s *JsonSlice) GetSliceOfStringsWithDefault(index int, defaultValue []string) ([]string, error)

GetSliceOfStringsWithDefault retrieves, from the slice, a []string at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice or if any value in the slice is not a string.

func (*JsonSlice) GetSliceWithDefault

func (s *JsonSlice) GetSliceWithDefault(index int, defaultValue JsonSlice) (JsonSlice, error)

GetSliceWithDefault retrieves, from the slice, a JsonSlice at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a JsonSlice.

func (*JsonSlice) GetString

func (s *JsonSlice) GetString(index int) (string, error)

GetString retrieves, from the slice, a string at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a string.

func (*JsonSlice) GetStringAtPath

func (s *JsonSlice) GetStringAtPath(path string) (string, error)

GetStringAtPath retrieves, from the slice, a string at the specified path. It will return an error if the path is invalid or if the value at the path is not a string. Note that slice paths should always begin with an array index. e.g. "[0].keyForString" (slice of maps with string value) or "[0][0]" (slice of slices of string values)

func (*JsonSlice) GetStringAtPathWithDefault

func (s *JsonSlice) GetStringAtPathWithDefault(path string, defaultValue string) (string, error)

GetStringAtPathWithDefault retrieves, from the slice, a string at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. It will return an error if the value at the path is not a string. Note that slice paths should always begin with an array index. e.g. "[0].keyForString" (slice of maps with string value) or "[0][0]" (slice of slices of string values)

func (*JsonSlice) GetStringWithDefault

func (s *JsonSlice) GetStringWithDefault(index int, defaultValue string) (string, error)

GetStringWithDefault retrieves, from the slice, a string at the specified index. It will return an error if the index is out of bounds for the slice or if the value at the index is not a string.

func (*JsonSlice) GetValue

func (s *JsonSlice) GetValue(index int) (interface{}, error)

GetValue retrieves, from the slice, an object of any type at the specified index. It will return an error if the index is out of bounds for the slice.

func (*JsonSlice) GetValueAtPath

func (s *JsonSlice) GetValueAtPath(path string) (interface{}, error)

GetValueAtPath retrieves, from the slice, an object of any type at the specified path. It will return an error if the path is invalid. Note that slice paths should always begin with an array index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) GetValueAtPathWithDefault

func (s *JsonSlice) GetValueAtPathWithDefault(path string, defaultValue interface{}) interface{}

GetValueAtPathWithDefault retrieves, from the slice, an object of any type at the specified path. If the value cannot be found for any reason (including an invalid path), then it returns the default value. Note that slice paths should always begin with an array index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) GetValueWithDefault

func (s *JsonSlice) GetValueWithDefault(index int, defaultValue interface{}) interface{}

GetValueWithDefault retrieves, from the slice, an object of any type at the specified index. If the index is out of bounds, then it returns the default value.

func (*JsonSlice) Map

func (s *JsonSlice) Map(mapMapFn MapMapFn, sliceMapFn SliceMapFn) JsonSlice

Map recursively applies mapping functions to a map and returns the new, transformed map. See MapMapFn and SliceMapFn for explanations of the mapping function parameters. Either or both may be nil, but note that slices may contain maps, which is why JsonSlice.Map() allows you to specify mapping functions for both slices and maps.

func (*JsonSlice) SetBool

func (s *JsonSlice) SetBool(index int, value bool) error

SetBool sets a bool at the specified index in the slice. It will not grow the slice, and it will return an error if the index is out of bounds for the slice.

func (*JsonSlice) SetBoolAtPath

func (s *JsonSlice) SetBoolAtPath(path string, value bool) error

SetBoolAtPath sets a bool at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that slice paths should always begin with an index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) SetFloat

func (s *JsonSlice) SetFloat(index int, value float64) error

SetFloat sets a float at the specified index in the slice. It will not grow the slice, and it will return an error if the index is out of bounds for the slice.

func (*JsonSlice) SetFloatAtPath

func (s *JsonSlice) SetFloatAtPath(path string, value float64) error

SetFloatAtPath sets a float at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that slice paths should always begin with an index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) SetInt

func (s *JsonSlice) SetInt(index int, value int64) error

SetInt sets an int at the specified index in the slice. It will not grow the slice, and it will return an error if the index is out of bounds for the slice.

func (*JsonSlice) SetIntAtPath

func (s *JsonSlice) SetIntAtPath(path string, value int64) error

SetIntAtPath sets an int at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that slice paths should always begin with an index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) SetMap

func (s *JsonSlice) SetMap(index int, value JsonMap) error

SetMap sets a JsonMap at the specified index in the slice. It will not grow the slice, and it will return an error if the index is out of bounds for the slice. Use caution with this method. If you add a map that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the slice.

func (*JsonSlice) SetMapAtPath

func (s *JsonSlice) SetMapAtPath(path string, value JsonMap) error

SetMapAtPath sets a JsonMap at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Use caution with this method. If you add a map that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the slice. Note that slice paths should always begin with an index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) SetSlice

func (s *JsonSlice) SetSlice(index int, value JsonSlice) error

SetSlice sets a JsonSlice at the specified index in the slice. It will not grow the slice, and it will return an error if the index is out of bounds for the slice. Use caution with this method. If you add a slice that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the slice.

func (*JsonSlice) SetSliceAtPath

func (s *JsonSlice) SetSliceAtPath(path string, value JsonSlice) error

SetSliceAtPath ses a JsonSlice at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Use caution with this method. If you add a slice that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the slice. Note that slice paths should always begin with an index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) SetString

func (s *JsonSlice) SetString(index int, value string) error

SetString sets a string at the specified index in the slice. It will not grow the slice, and it will return an error if the index is out of bounds for the slice.

func (*JsonSlice) SetStringAtPath

func (s *JsonSlice) SetStringAtPath(path string, value string) error

SetStringAtPath sets a string at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Note that slice paths should always begin with an index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) SetValue

func (s *JsonSlice) SetValue(index int, value interface{}) error

SetValue sets an object of any type at the specified index in the slice. It will not grow the slice, and it will return an error if the index is out of bounds for the slice. Use caution with this method. If you add an object that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the slice.

func (*JsonSlice) SetValueAtPath

func (s *JsonSlice) SetValueAtPath(path string, value interface{}) error

SetValueAtPath sets an object of any type at the specified path. It will attempt to create missing intermediate map elements of the path. It will fail to create missing intermediate slice elements. Use caution with this method. If you add an object that contains invalid Json elements (e.g. arbitrary structs or pointers to objects), then you may break the ability to traverse the slice. Note that slice paths should always begin with an index. e.g. "[0].keyForValue" (slice of maps with value) or "[0][0]" (slice of slices of values)

func (*JsonSlice) ToIoWriter

func (s *JsonSlice) ToIoWriter(jsonWriter io.Writer, pretty bool, escapeHtml bool) error

func (*JsonSlice) ToJsonBytes

func (s *JsonSlice) ToJsonBytes(pretty bool, escapeHtml bool) ([]byte, error)

func (*JsonSlice) ToJsonString

func (s *JsonSlice) ToJsonString(pretty bool, escapeHtml bool) (string, error)

type MapMapFn

type MapMapFn func(elementPath []interface{}, ancestorSliceIndex int, key string, value interface{}) (
	newKey string, newValue interface{},
)

MapMapFn is the signature for a callback that the JsonMap.Map() function recursively applies to map keys/values. Callback implementations may mutate the key and value parameters by returning new values for either or both. The callback may also delete a key by returning an empty string for the new key name.

As mapping proceeds, the elementPath parameter reflects the path of the current element's parent. The elementPath can be a mix of strings and ints, where strings represent map keys and ints represent slice indices. If the current map is located within a slice (either directly or as a nested element of an element within a slice), the ancestorSliceIndex parameter will be >= 0 to represent the index of the current map within the nearest slice (otherwise it will be < 0). This can be used, for example, to set a map's key or value to something reflecting its position in the slice. You could extract ancestorSliceIndex from elementPath; however, it is provided separately as a convenience.

Example:

{
  "Key1": [
    {
      "Key2": {
        "Key3: 1
      }
    },
    {
      "Key4": {
        "Key5: 2
      }
    }
  ]
}

When MapMapFn is called for Key1, elementPath will be [] and ancestorSliceIndex will be -1 When MapMapFn is called for Key3, elementPath will be ["Key1", 0, "Key2"] and ancestorSliceIndex will be 0 When MapMapFn is called for Key5, elementPath will be ["Key1", 1, "Key4"] and ancestorSliceIndex will be 1

type SliceMapFn

type SliceMapFn func(elementPath []interface{}, ancestorSliceIndex int, index int, value interface{}) (
	newValue interface{}, keepValue bool,
)

SliceMapFn is the signature for a callback that the JsonMap.Map() function recursively applies to slice values. Callback implementations may mutate the value by returning a new one. Callbacks may also drop a value from a slice by returning false for the "keepValue" return value.

As mapping proceeds, the elementPath parameter reflects the path of the current element's parent. The elementPath can be a mix of strings and ints, where strings represent map keys and ints represent slice indices. If the current slice is located within a slice (either directly or as a nested element of an element within a slice), the ancestorSliceIndex parameter will be >= 0 to represent the index of the current slice within the nearest slice (otherwise it will be < 0). This can be used, for example, to set a slice's value to something reflecting its position in the slice. You could extract ancestorSliceIndex from elementPath; however, it is provided separately as a convenience.

Example:

{
  "Key1": [
    {
      "Key2": {
        "Key3: 1
      }
    },
    {
      "Key4": {
        "Key5: 2
      }
    }
  ]
}

When MapMapFn is called for Key1, elementPath will be [] and ancestorSliceIndex will be -1 When MapMapFn is called for Key3, elementPath will be ["Key1", 0, "Key2"] and ancestorSliceIndex will be 0 When MapMapFn is called for Key5, elementPath will be ["Key1", 1, "Key4"] and ancestorSliceIndex will be 1

Jump to

Keyboard shortcuts

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