jsonutil

package
v1.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 5 Imported by: 0

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

func Decode(st string) any

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 Diff

func Diff(src, target map[string]any) string

Diff compares two `map[string]any` objects strictly and collects differences.

func LooksLikeJSON

func LooksLikeJSON(st string) bool

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

func Match

func Match(src, target map[string]any) bool

Match compares two `map[string]any` objects strictly. All fields in `src` and `target` must match, including structure and values.

func Parse

func Parse(s string) (any, error)

Parse parses a JSON string into a map[string]any or []any.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL