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 unmarshals a JSON string into either a map[string]any (object input) or []any (array input). 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": "mustMarshalJSON error: ..."}
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.
Click to show internal directories.
Click to hide internal directories.