Documentation ¶
Overview ¶
Package json is a representation of a JSON object
SPDX-License-Identifier: Apache-2.0
Index ¶
- Variables
- func ParsePath(p string) (fn func(Value) (Value, error), err error)
- type NumberString
- type Type
- type Value
- func BoolToValue(val bool) Value
- func MapToValue[T map[string]any | map[string]Value](val T) (mval Value, err error)
- func MustMapToValue[T map[string]any | map[string]Value](val T) Value
- func MustNumberToValue[T NumberString | constraint.Numeric](val T) Value
- func MustSliceToValue[T []any | []Value](val T) Value
- func MustToValue[...](val T) Value
- func NumberToValue[T NumberString | constraint.Numeric](val T) (Value, error)
- func SliceToValue[T []any | []Value](val T) (sval Value, err error)
- func StringToValue(val string) Value
- func ToValue[...](val T) (res Value, err error)
- func (jv Value) AsBool() bool
- func (jv Value) AsMap() map[string]Value
- func (jv Value) AsNumber() NumberString
- func (jv Value) AsSlice() []Value
- func (jv Value) AsString() string
- func (jv Value) IsDocument() bool
- func (jv Value) IsNull() bool
- func (jv Value) ToAny() any
- func (jv Value) ToMap() map[string]any
- func (jv Value) ToSlice(visitor ...func(Value) any) []any
- func (jv Value) Type() Type
Constants ¶
This section is empty.
Variables ¶
var ( TrueValue = Value{/* contains filtered or unexported fields */} FalseValue = Value{/* contains filtered or unexported fields */} NullValue = Value{/* contains filtered or unexported fields */} )
Constant values for a invalid, true, false, and null
Functions ¶
func ParsePath ¶
Convert a path into an Object or Array, such as .addresses[3].city, or [3].city, into a func(Value) Value that performs the lookup on an input Value. If any path part does not exist in the Value passed to the func, an Invalid Value is returned. If the given path is not valid, an error is returned.
Types ¶
type NumberString ¶
type NumberString string
NumberString is a type that allows a plain string to be considered a JSON Number. Allows differentiation between an actual string value, and a string that is really a number value.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents any kind of JSON value - object, array, string, number, boolean, null
func MapToValue ¶
MapToValue converts a map[string]any to a Value of type Object, where the map values must be: - map[string]any for a sub Object - []any for a sub Array - string for a String - NumberString or any constraint.Numeric type for a Number - bool for a Boolean - nil for a Null
Any other key value results in (Invalid Value, error)
func MustMapToValue ¶
MustMapToValue is a must version of MapToValue
func MustNumberToValue ¶
func MustNumberToValue[T NumberString | constraint.Numeric](val T) Value
MustNumberToValue is a must version of NumberToValue
func MustSliceToValue ¶
MustSliceToValue is a must version of SliceToValue
func MustToValue ¶
func MustToValue[T map[string]any | map[string]Value | []any | []Value | string | NumberString | constraint.Numeric | bool](val T) Value
MustToValue is a must version of ToValue
func NumberToValue ¶
func NumberToValue[T NumberString | constraint.Numeric](val T) (Value, error)
NumberToValue converts any numeric type into a Value
func SliceToValue ¶
SliceToValue converts a []any to a Value of type Array, where the slice values must be the same as map key values (see MapToValue).
Any other slice value results in the (Invalid Value, error)
func StringToValue ¶
StringToValue converts a string to a Value
func ToValue ¶
func ToValue[T map[string]any | map[string]Value | []any | []Value | string | NumberString | constraint.Numeric | bool](val T) (res Value, err error)
ToValue converts value types any into a Value
func (Value) AsBool ¶
AsBoolean returns a bool representation of a Value. Panics if the Value is not a boolean.
func (Value) AsMap ¶
AsMap returns a map representation of a Value. Panics if the Value is not an object.
func (Value) AsNumber ¶
func (jv Value) AsNumber() NumberString
AsNumber returns a NumberString representation of a Value. Panics if the Value is not a number.
func (Value) AsSlice ¶
AsSlice returns a slice representation of a Value. Panics if the Value is not an array.
func (Value) AsString ¶
AsString returns a string representation of a Value. Panics if the Value is not a string, number, or boolean.
func (Value) IsDocument ¶
IsDocument returns true if a Value is a document (Object or Array)
func (Value) ToAny ¶
ToAny converts the Value to the approriate go type: Object = map[string]any Array = []any String = string Number = NumberString Boolean = bool Null = nil
func (Value) ToMap ¶
ToMap returns a map[string]any representation of a Value. Panics if the Value is not an object.