jsonbasics

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 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)

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)

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