Documentation
¶
Overview ¶
Package jsonutil decodes and compares the JSON values that actions return.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode decodes a JSON object or array as Parse does. On failure it returns a map[string]any with an error_message instead of an error, so callers can surface the parse error in place of the data.
Example:
result := Decode(`{"name": "John"}`)
// result: map[string]any{"name": "John"}
result := Decode(`[{"id": 1}, {"id": 2}]`)
// result: []any{map[string]any{"id": float64(1)}, map[string]any{"id": float64(2)}}
result := Decode(`invalid json`)
// result: map[string]any{"error_message": "invalid JSON: ..."}
func Diff ¶
Diff compares two `map[string]any` objects strictly and describes the first difference it finds, walking keys in sorted order so the same input always reports the same difference. It returns an error when `target` holds a "/regex/" string that does not compile.
func LooksLikeJSON ¶
LooksLikeJSON checks if a string appears to be JSON by examining its first and last characters. This is a simple heuristic check and does not validate actual JSON syntax.
Example:
LooksLikeJSON(`{"key": "value"}`) // true
LooksLikeJSON(`["item1", "item2"]`) // true
LooksLikeJSON(`{key: value}`) // true (note: this is actually invalid JSON but has JSON-like brackets)
LooksLikeJSON(`hello world`) // false
Types ¶
This section is empty.