json

package
v1.60.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package json is forked from the Go standard library to enable us to find the field of a struct that a given JSON key maps to.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertInterfaceNumbers

func ConvertInterfaceNumbers(v *interface{}, depth int) error

ConvertInterfaceNumbers converts any json.Number values to int64 or float64. Values which are map[string]interface{} or []interface{} are recursively visited

func ConvertMapNumbers

func ConvertMapNumbers(m map[string]interface{}, depth int) error

ConvertMapNumbers traverses the map, converting any json.Number values to int64 or float64. values which are map[string]interface{} or []interface{} are recursively visited

func ConvertSliceNumbers

func ConvertSliceNumbers(s []interface{}, depth int) error

ConvertSliceNumbers traverses the slice, converting any json.Number values to int64 or float64. values which are map[string]interface{} or []interface{} are recursively visited

func LookupPatchMetadataForStruct

func LookupPatchMetadataForStruct(t reflect.Type, jsonField string) (
	elemType reflect.Type, patchStrategies []string, patchMergeKey string, e error)

Finds the patchStrategy and patchMergeKey struct tag fields on a given struct field given the struct type and the JSON name of the field. It returns field type, a slice of patch strategies, merge key and error. TODO: fix the returned errors to be introspectable.

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal delegates to json.Marshal It is only here so this package can be a drop-in for common encoding/json uses

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal unmarshals the given data. Object keys are case-sensitive. Numbers decoded into interface{} fields are converted to int64 or float64.

Upstream delegates to sigs.k8s.io/json's case-sensitive, int-preserving decoder. Here encoding/json decodes with UseNumber and the conversion below turns each json.Number into int64 or float64 the same way. encoding/json matches struct fields case-insensitively, so only the untyped targets the patch code decodes into are accepted; any other target is an error rather than a silently different decode.

Types

This section is empty.

Jump to

Keyboard shortcuts

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