jsonrequire

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Match

func Match(t testing.TB, expectedTemplateFormat string, params map[string]any, actual string)

Match helps to make assertions on JSON strings when some values are not known in advance. For example, when we do the assertion on JSON serialized models, we can't predict the values of fields like IDs or timestamps. In such cases, we can use a "template" with placeholders for these values. See matcher_test.go for examples

Types

type Getter

type Getter struct {
	// contains filtered or unexported fields
}

Getter allows to get values from the JSON data.

func NewGetterWithJSON

func NewGetterWithJSON(t testing.TB, jsonString string) *Getter

NewGetterWithJSON creates a new Getter based on JSON string

func (*Getter) GetAsType

func (g *Getter) GetAsType(xpath string, target any)

GetAsType gets a value from the data and unmarshals it into the target.

func (*Getter) GetField

func (g *Getter) GetField(xpath string) any

GetField returns a value from the data.

func (*Getter) GetInt

func (g *Getter) GetInt(xpath string) int

GetField returns a value from the data.

func (*Getter) GetString

func (g *Getter) GetString(xpath string) string

GetString returns a string value from the data.

Jump to

Keyboard shortcuts

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