jsonbasics

package
v0.1.41 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToJSONInterface added in v0.1.12

func ConvertToJSONInterface(data *yaml.Node) *interface{}

func ConvertToJSONobject added in v0.1.12

func ConvertToJSONobject(data *yaml.Node) map[string]interface{}

func ConvertToYamlNode added in v0.1.12

func ConvertToYamlNode(data interface{}) *yaml.Node

func DeepCopyArray added in v0.1.10

func DeepCopyArray(data []interface{}) []interface{}

DeepCopyArray implements a poor man's deepcopy by jsonify/de-jsonify

func DeepCopyObject added in v0.1.10

func DeepCopyObject(data map[string]interface{}) map[string]interface{}

DeepCopyObject implements a poor man's deepcopy by jsonify/de-jsonify

func GetBoolField

func GetBoolField(object map[string]interface{}, fieldName string) (bool, error)

GetBoolField returns a boolean from an object field. Returns an error if the field is not a boolean, or is not found.

func GetBoolIndex

func GetBoolIndex(arr []interface{}, index int) (bool, error)

GetBoolIndex returns a boolean-value from an array index. Returns an error if the entry is not a boolean.

func GetFloat64Field added in v0.1.28

func GetFloat64Field(object map[string]interface{}, fieldName string) (float64, error)

GetFloat64Field returns a float64 from an object field. Returns an error if the field is not a float, or is not found.

func GetFloat64Index added in v0.1.28

func GetFloat64Index(arr []interface{}, index int) (float64, error)

GetFloat64Index returns a float64-value from an array index. Returns an error if the entry is not a float.

func GetInt64Field added in v0.1.32

func GetInt64Field(object map[string]interface{}, fieldName string) (int64, error)

GetInt64Field returns an int64 from an object field. Returns an error if the field is not an integer, or is not found.

func GetInt64Index added in v0.1.32

func GetInt64Index(arr []interface{}, index int) (int64, error)

GetInt64Index returns an int64-value from an array index. Returns an error if the entry is not an integer.

func GetObjectArrayField

func GetObjectArrayField(object map[string]interface{}, fieldName string) ([]map[string]interface{}, error)

GetObjectArrayField returns a new slice containing all objects from the array referenced by fieldName. If the field is not an array, it returns an error. If the field doesn't exist it returns an empty array. Any entry in the array that is not an object will be omitted from the returned slice.

func GetStringArrayField added in v0.1.10

func GetStringArrayField(object map[string]interface{}, fieldName string) ([]string, error)

GetStringArrayField returns a new slice containing all strings from the array referenced by fieldName. If the field is not an array, it returns an error. If the field doesn't exist it returns an empty array. Any entry in the array that is not a string will be omitted from the returned slice.

func GetStringField

func GetStringField(object map[string]interface{}, fieldName string) (string, error)

GetStringField returns a string-value from an object field. Returns an error if the field is not a string, or is not found.

func GetStringIndex

func GetStringIndex(arr []interface{}, index int) (string, error)

GetStringIndex returns a string-value from an array index. Returns an error if the entry is not a string.

func GetUInt64Field added in v0.1.28

func GetUInt64Field(object map[string]interface{}, fieldName string) (uint64, error)

GetUInt64Field returns a uint64 from an object field. Returns an error if the field is not a unsigned integer, or is not found.

func GetUInt64Index added in v0.1.28

func GetUInt64Index(arr []interface{}, index int) (uint64, error)

GetUInt64Index returns a uint64-value from an array index. Returns an error if the entry is not an unsigned integer.

func RemoveObjectFromArrayByFieldValue

func RemoveObjectFromArrayByFieldValue(inArr interface{},
	fieldName string, fieldValue string, occurrences int,
) (interface{}, int, error)

RemoveObjectFromArrayByFieldValue returns a slice in which objects that match the field value are removed. Returns; new slice, # of removals, err. occurrences determines the maximum number of items to remove, use -1 for unlimited. Only returns an error if inArr is given (non-nil), and it is not an array/slice. But even then it still returns the input value, so it is transparent.

func SetObjectArrayField added in v0.1.14

func SetObjectArrayField(object map[string]interface{}, fieldName string, objectArray []map[string]interface{})

SetObjectArrayField sets an array in a parsed json object. This ensure it is of type []interface{}, such that a next call to GetObjectArrayField will work. If 'objectArray' is nil, then the field is deleted from the object.

func ToArray

func ToArray(arr interface{}) ([]interface{}, error)

ToArray returns the array, or nil+err

func ToObject

func ToObject(obj interface{}) (map[string]interface{}, error)

ToObject returns the object, if it was one, or nil+err.

Types

This section is empty.

Jump to

Keyboard shortcuts

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