MCPcopy Create free account
hub / github.com/expr-lang/expr / JSONEq

Function JSONEq

internal/testify/assert/assertions.go:1764–1779  ·  view source on GitHub ↗

JSONEq asserts that two JSON strings are equivalent. assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)

(t TestingT, expected string, actual string, msgAndArgs ...interface{})

Source from the content-addressed store, hash-verified

1762//
1763// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
1764func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool {
1765 if h, ok := t.(tHelper); ok {
1766 h.Helper()
1767 }
1768 var expectedJSONAsInterface, actualJSONAsInterface interface{}
1769
1770 if err := json.Unmarshal([]byte(expected), &expectedJSONAsInterface); err != nil {
1771 return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
1772 }
1773
1774 if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
1775 return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
1776 }
1777
1778 return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...)
1779}
1780
1781func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) {
1782 t := reflect.TypeOf(v)

Calls 5

SprintfMethod · 0.80
FailFunction · 0.70
EqualFunction · 0.70
HelperMethod · 0.45
ErrorMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…