Documentation
¶
Overview ¶
Package jsonx provides helpers for json in/out operations
Index ¶
- Variables
- func ApplyOverlay[T any](base T, overlay any) (T, error)
- func CloneRawMessage(raw json.RawMessage) json.RawMessage
- func DecodeAnyOrNil(raw json.RawMessage) any
- func DeepMerge(base, patch json.RawMessage) (json.RawMessage, bool, error)
- func IsEmptyRawMessage(raw json.RawMessage) bool
- func MergeObjectMap(base json.RawMessage, patch map[string]json.RawMessage) (json.RawMessage, bool, error)
- func RoundTrip(input any, output any) error
- func SetObjectKey(base json.RawMessage, key string, value any) (json.RawMessage, bool, error)
- func ToMap(value any) (map[string]any, error)
- func ToRawMap(value any) (map[string]json.RawMessage, error)
- func ToRawMessage(value any) (json.RawMessage, error)
- func UnmarshalIfPresent(raw json.RawMessage, output any) error
- func ValidateSchema(schema any, document any) (*gojsonschema.Result, error)
- func ValidationErrorStrings(result *gojsonschema.Result) []string
Constants ¶
This section is empty.
Variables ¶
var ( // ErrObjectExpected is returned when a JSON round-trip does not produce an object ErrObjectExpected = errors.New("json value is not an object") // ErrKeyRequired is returned when a JSON object key is empty ErrKeyRequired = errors.New("json key is required") )
Functions ¶
func ApplyOverlay ¶ added in v1.15.0
ApplyOverlay applies a JSON overlay to an existing typed value
func CloneRawMessage ¶ added in v1.15.0
func CloneRawMessage(raw json.RawMessage) json.RawMessage
CloneRawMessage copies a raw JSON document to avoid accidental aliasing
func DecodeAnyOrNil ¶ added in v1.15.0
func DecodeAnyOrNil(raw json.RawMessage) any
DecodeAnyOrNil decodes raw JSON to an untyped value or returns nil on failure/empty input
func DeepMerge ¶ added in v1.15.0
func DeepMerge(base, patch json.RawMessage) (json.RawMessage, bool, error)
DeepMerge deep-merges patch into base and reports whether the document changed. Both arguments must be JSON objects. Returns the merged document and a boolean indicating whether the result differs from base
func IsEmptyRawMessage ¶ added in v1.15.0
func IsEmptyRawMessage(raw json.RawMessage) bool
IsEmptyRawMessage reports whether a raw JSON message is empty or null
func MergeObjectMap ¶ added in v1.15.0
func MergeObjectMap(base json.RawMessage, patch map[string]json.RawMessage) (json.RawMessage, bool, error)
MergeObjectMap shallow-merges a raw JSON object with the supplied top-level patch map
func SetObjectKey ¶ added in v1.15.0
func SetObjectKey(base json.RawMessage, key string, value any) (json.RawMessage, bool, error)
SetObjectKey sets or replaces one top-level key in a raw JSON object
func ToRawMap ¶ added in v1.15.0
func ToRawMap(value any) (map[string]json.RawMessage, error)
ToRawMap converts an arbitrary value into a JSON object map of raw values.
func ToRawMessage ¶ added in v1.15.0
func ToRawMessage(value any) (json.RawMessage, error)
ToRawMessage converts an arbitrary value into a raw JSON document
func UnmarshalIfPresent ¶ added in v1.15.0
func UnmarshalIfPresent(raw json.RawMessage, output any) error
UnmarshalIfPresent unmarshals raw JSON when it is non-empty
func ValidateSchema ¶ added in v1.15.0
func ValidateSchema(schema any, document any) (*gojsonschema.Result, error)
ValidateSchema validates a JSON document against a JSON schema and returns the raw gojsonschema result for caller-specific error handling.
func ValidationErrorStrings ¶ added in v1.15.0
func ValidationErrorStrings(result *gojsonschema.Result) []string
ValidationErrorStrings converts schema validation errors into string messages.
Types ¶
This section is empty.