Json
Asserting JSON Documents
Assertions
All links point to https://pkg.go.dev/github.com/go-openapi/testify/v2
This domain exposes 5 functionalities. Generic assertions are marked with a .
JSONEq
JSONEq asserts that two JSON strings are semantically equivalent.
Expected and actual must be valid JSON.
For dynamic redaction of the input text via a callback, use JSONEqT.
| Signature | Usage |
|---|---|
assert.JSONEq(t T, expected string, actual string, msgAndArgs ...any) bool | package-level function |
assert.JSONEqf(t T, expected string, actual string, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).JSONEq(expected string, actual string) bool | method variant |
assert.(*Assertions).JSONEqf(expected string, actual string, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.JSONEq(t T, expected string, actual string, msgAndArgs ...any) bool | package-level function |
require.JSONEqf(t T, expected string, actual string, msg string, args ...any) bool | formatted variant |
require.(*Assertions).JSONEq(expected string, actual string) bool | method variant |
require.(*Assertions).JSONEqf(expected string, actual string, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.JSONEq(t T, expected string, actual string, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#JSONEq
JSONEqBytes
JSONEqBytes asserts that two JSON slices of bytes are semantically equivalent.
Expected and actual must be valid JSON.
| Signature | Usage |
|---|---|
assert.JSONEqBytes(t T, expected []byte, actual []byte, msgAndArgs ...any) bool | package-level function |
assert.JSONEqBytesf(t T, expected []byte, actual []byte, msg string, args ...any) bool | formatted variant |
assert.(*Assertions).JSONEqBytes(expected []byte, actual []byte) bool | method variant |
assert.(*Assertions).JSONEqBytesf(expected []byte, actual []byte, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
require.JSONEqBytes(t T, expected []byte, actual []byte, msgAndArgs ...any) bool | package-level function |
require.JSONEqBytesf(t T, expected []byte, actual []byte, msg string, args ...any) bool | formatted variant |
require.(*Assertions).JSONEqBytes(expected []byte, actual []byte) bool | method variant |
require.(*Assertions).JSONEqBytesf(expected []byte, actual []byte, msg string, args ..any) | method formatted variant |
| Signature | Usage |
|---|---|
assertions.JSONEqBytes(t T, expected []byte, actual []byte, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#JSONEqBytes
Maintainer Note
Proposal for enhancement.
We could use and indirection for users to inject their favorite JSON library like we do for YAML.
JSONEqT[EDoc, ADoc RText]
JSONEqT asserts that two JSON documents are semantically equivalent.
The expected and actual arguments may be string or []byte. They do not need to be of the same type.
Expected and actual must be valid JSON.
NOTE: passed values (expected, actual) may be wrapped as functions to redact the input text dynamically.
| Signature | Usage |
|---|---|
assert.JSONEqT[EDoc, ADoc RText](t T, expected EDoc, actual ADoc, msgAndArgs ...any) bool | package-level function |
assert.JSONEqTf[EDoc, ADoc RText](t T, expected EDoc, actual ADoc, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
require.JSONEqT[EDoc, ADoc RText](t T, expected EDoc, actual ADoc, msgAndArgs ...any) bool | package-level function |
require.JSONEqTf[EDoc, ADoc RText](t T, expected EDoc, actual ADoc, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
assertions.JSONEqT[EDoc, ADoc RText](t T, expected EDoc, actual ADoc, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#JSONEqT
JSONMarshalAsT[EDoc RText]
JSONMarshalAsT wraps JSONEqT after json.Marshal.
The input JSON may be a string or []byte.
It fails if the marshaling returns an error or if the expected JSON bytes differ semantically from the expected ones.
NOTE: passed expected value may be wrapped as a function to redact the input text dynamically.
| Signature | Usage |
|---|---|
assert.JSONMarshalAsT[EDoc RText](t T, expected EDoc, object any, msgAndArgs ...any) bool | package-level function |
assert.JSONMarshalAsTf[EDoc RText](t T, expected EDoc, object any, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
require.JSONMarshalAsT[EDoc RText](t T, expected EDoc, object any, msgAndArgs ...any) bool | package-level function |
require.JSONMarshalAsTf[EDoc RText](t T, expected EDoc, object any, msg string, args ...any) bool | formatted variant |
| Signature | Usage |
|---|---|
assertions.JSONMarshalAsT[EDoc RText](t T, expected EDoc, object any, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#JSONMarshalAsT
JSONUnmarshalAsT[Object any, ADoc RText]
JSONUnmarshalAsT wraps Equal after json.Unmarshal.
The input JSON may be a string or []byte.
It fails if the unmarshaling returns an error or if the resulting object is not equal to the expected one.
Be careful not to wrap the expected object into an “any” interface if this is not what you expected: the unmarshaling would take this type to unmarshal as a mapstringany.
NOTE: passed jazon value may be wrapped as a function to redact the input JSON dynamically.
| Signature | Usage |
|---|---|
assertions.JSONUnmarshalAsT[Object any, ADoc RText](t T, expected Object, jazon ADoc, msgAndArgs ...any) bool | internal implementation |
Source: github.com/go-openapi/testify/v2/internal/assertions#JSONUnmarshalAsT
Generated with github.com/go-openapi/testify/codegen/v2