jsonutil

package
v1.33.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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(s string) any

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

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

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

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, error)

Match compares two `map[string]any` objects strictly. All fields in `src` and `target` must match, including structure and values. It returns an error when `target` holds a "/regex/" string that does not compile.

func Parse

func Parse(s string) (any, error)

Parse decodes a JSON object into a map[string]any or a JSON array into a []any, surrounding whitespace aside. It refuses an empty string, any other JSON value, such as a string, a number or null, and invalid JSON.

Types

This section is empty.

Jump to

Keyboard shortcuts

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