jsonbasics

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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)

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)

func GetStringIndex

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

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