Documentation
¶
Index ¶
- func AsArray(objOrArr interface{}, ptr JSONPointer) ([]interface{}, error)
- func AsBool(objOrArr interface{}, ptr JSONPointer) (bool, error)
- func AsFloat32(objOrArr interface{}, ptr JSONPointer) (float32, error)
- func AsFloat64(objOrArr interface{}, ptr JSONPointer) (float64, error)
- func AsFloat64Array(objOrArr interface{}, ptr JSONPointer) ([]float64, error)
- func AsInt(objOrArr interface{}, ptr JSONPointer) (int, error)
- func AsInt32(objOrArr interface{}, ptr JSONPointer) (int32, error)
- func AsInt64(objOrArr interface{}, ptr JSONPointer) (int64, error)
- func AsIntArray(objOrArr interface{}, ptr JSONPointer) ([]int, error)
- func AsObject(objOrArr interface{}, ptr JSONPointer) (map[string]interface{}, error)
- func AsString(objOrArr interface{}, ptr JSONPointer) (string, error)
- func AsStringArray(objOrArr interface{}, ptr JSONPointer) ([]string, error)
- func Evaluate(objOrArr interface{}, ptr JSONPointer) (interface{}, error)
- func MustArray(v []interface{}, err error) []interface{}
- func MustBool(v bool, err error) bool
- func MustFloat32(v float32, err error) float32
- func MustFloat64(v float64, err error) float64
- func MustInt(v int, err error) int
- func MustInt32(v int32, err error) int32
- func MustInt64(v int64, err error) int64
- func MustObject(v map[string]interface{}, err error) map[string]interface{}
- func MustString(v string, err error) string
- func MustStringArray(v []string, err error) []string
- func TryArray(v []interface{}, err error) []interface{}
- func TryBool(v bool, err error) bool
- func TryFloat32(v float32, err error) float32
- func TryFloat64(v float64, err error) float64
- func TryInt(v int, err error) int
- func TryInt32(v int32, err error) int32
- func TryInt64(v int64, err error) int64
- func TryObject(v map[string]interface{}, err error) map[string]interface{}
- func TryString(v string, err error) string
- func TryStringArray(v []string, err error) []string
- func Unescape(str JSONPointerToken) string
- type JSONPointer
- type JSONPointerToken
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsArray ¶
func AsArray(objOrArr interface{}, ptr JSONPointer) ([]interface{}, error)
AsArray evaluates the JSONPointer and unwraps either []interface{} or *[]interface{} slices. Any other slice types are unboxed to []interface{}. If value is not a slice type at all, the value is inserted into a one-element interface slice.
- only evaluation errors are returned as errors.
func AsBool ¶
func AsBool(objOrArr interface{}, ptr JSONPointer) (bool, error)
AsBool takes a JSONPointer and tries to interpret the result as a bool. Anything else is interpreted as false.
- only evaluation errors are returned as errors.
func AsFloat32 ¶ added in v0.0.2
func AsFloat32(objOrArr interface{}, ptr JSONPointer) (float32, error)
AsFloat32 takes a JSONPointer and tries to interpret the result as a float. The following rules are applied:
- numbers are converted to a float
- booleans are converted to 1|0
- null is converted NaN
- a non-resolvable value, returns also NaN
- arrays and objects are converted to NaN
- String() method is invoked, if available, and output parsed. Returns NaN if not parsable.
- Anything else is converted using sprintf and %v directive and tried to be parsed. Returns NaN if not parsable.
- only evaluation errors are returned as errors.
func AsFloat64 ¶ added in v0.0.2
func AsFloat64(objOrArr interface{}, ptr JSONPointer) (float64, error)
AsFloat64 takes a JSONPointer and tries to interpret the result as a float. The following rules are applied:
- numbers are converted to a float
- booleans are converted to 1|0
- null is converted NaN
- a non-resolvable value, returns also NaN
- arrays and objects are converted to NaN
- String() method is invoked, if available, and output parsed. Returns NaN if not parsable.
- Anything else is converted using sprintf and %v directive and tried to be parsed. Returns NaN if not parsable.
- only evaluation errors are returned as errors.
func AsFloat64Array ¶ added in v0.0.2
func AsFloat64Array(objOrArr interface{}, ptr JSONPointer) ([]float64, error)
AsFloat64Array evaluates the JSONPointer and tries to interpret any slice value as float (see AsFloat) for rules
- only evaluation errors are returned as errors.
func AsInt ¶
func AsInt(objOrArr interface{}, ptr JSONPointer) (int, error)
AsInt takes a JSONPointer and tries to interpret the result as an int using the rules of AsFloat. NaN is treated as 0.
- only evaluation errors are returned as errors.
func AsInt32 ¶ added in v0.0.2
func AsInt32(objOrArr interface{}, ptr JSONPointer) (int32, error)
AsInt32 takes a JSONPointer and tries to interpret the result as an int using the rules of AsFloat. NaN is treated as 0.
- only evaluation errors are returned as errors.
func AsInt64 ¶ added in v0.0.2
func AsInt64(objOrArr interface{}, ptr JSONPointer) (int64, error)
AsInt64 takes a JSONPointer and tries to interpret the result as an int using the rules of AsFloat. NaN is treated as 0.
- only evaluation errors are returned as errors.
func AsIntArray ¶
func AsIntArray(objOrArr interface{}, ptr JSONPointer) ([]int, error)
AsIntArray evaluates the JSONPointer and uses the AsFloatArray conversion rules but truncates to int. JSON does not support integers at all, just floats anyway. NaN values are treated as 0.
- only evaluation errors are returned as errors.
func AsObject ¶ added in v0.0.2
func AsObject(objOrArr interface{}, ptr JSONPointer) (map[string]interface{}, error)
AsArray evaluates the JSONPointer and unwraps map[string]interface{}. Any other slice types are unboxed to []interface{}. If value is not a map type at all, the value is inserted into a one-element map with the key value.
- only evaluation errors are returned as errors.
func AsString ¶
func AsString(objOrArr interface{}, ptr JSONPointer) (string, error)
AsString takes a JSONPointer and tries to interpret the result as a string. The following rules are applied:
- numbers are converted to the according string representation
- booleans are converted to true|false
- null is converted to the empty string
- a non-resolvable value, returns the empty string
- arrays and objects are converted into a json string
- String() methods are used, if available
- Anything else is converted using sprintf and %v directive
- only evaluation errors are returned as errors.
func AsStringArray ¶
func AsStringArray(objOrArr interface{}, ptr JSONPointer) ([]string, error)
AsStringArray evaluates the JSONPointer and tries to interpret any slice value as string (see AsString) for rules
- only evaluation errors are returned as errors.
func Evaluate ¶
func Evaluate(objOrArr interface{}, ptr JSONPointer) (interface{}, error)
Evaluate takes the json pointer and applies it to the given json object or array. Returns an error if the json pointer cannot be resolved.
func MustArray ¶ added in v0.0.2
func MustArray(v []interface{}, err error) []interface{}
MustArray is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustBool ¶ added in v0.0.2
MustBool is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustFloat32 ¶ added in v0.0.2
MustFloat32 is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustFloat64 ¶ added in v0.0.2
MustFloat64 is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustInt ¶ added in v0.0.2
MustInt is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustInt32 ¶ added in v0.0.2
MustInt32 is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustInt64 ¶ added in v0.0.2
MustInt32 is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustObject ¶ added in v0.0.2
MustObject is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustString ¶ added in v0.0.2
MustString is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func MustStringArray ¶ added in v0.0.2
MustStringArray is a go-like "expect macro" pattern. Panics in case of error, otherwise returns v.
func TryArray ¶ added in v0.0.2
func TryArray(v []interface{}, err error) []interface{}
TryArray is a go-like "try macro" pattern. Returns nil in case of error, otherwise v.
func TryBool ¶ added in v0.0.2
TryBool is a go-like "try macro" pattern. Returns false in case of error, otherwise v.
func TryFloat32 ¶ added in v0.0.2
TryFloat32 is a go-like "try macro" pattern. Returns +Inf in case of error, otherwise v.
func TryFloat64 ¶ added in v0.0.2
TryFloat64 is a go-like "try macro" pattern. Returns NaN in case of error, otherwise v.
func TryInt ¶ added in v0.0.2
TryInt is a go-like "try macro" pattern. Returns 0 in case of error, otherwise v.
func TryInt32 ¶ added in v0.0.2
TryInt32 is a go-like "try macro" pattern. Returns 0 in case of error, otherwise v.
func TryInt64 ¶ added in v0.0.2
TryInt32 is a go-like "try macro" pattern. Returns 0 in case of error, otherwise v.
func TryObject ¶ added in v0.0.2
TryObject is a go-like "try macro" pattern. Returns empty map in case of error, otherwise v.
func TryString ¶ added in v0.0.2
TryString is a go-like "try macro" pattern. Returns the empty string in case of error, otherwise v.
func TryStringArray ¶ added in v0.0.2
TryStringArray is a go-like "try macro" pattern. Returns nil in case of error, otherwise v.
func Unescape ¶
func Unescape(str JSONPointerToken) string
Unescape takes a token and returns the original string. ~0 becomes ~ and ~1 becomes /
Types ¶
type JSONPointer ¶
type JSONPointer = string
A JSONPointer specifies a specific value within a JSON document. See https://tools.ietf.org/html/rfc6901 for the specification.
type JSONPointerToken ¶
type JSONPointerToken = string
A JSONPointerToken is a single element or token of a JSONPointer
func Escape ¶
func Escape(str string) JSONPointerToken
Escape takes any string and returns a token. ~ becomes ~0 and / becomes ~1