MCPcopy Create free account
hub / github.com/stretchr/testify / JSONEq

Function JSONEq

assert/assertions.go:1807–1822  ·  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

1805//
1806// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
1807func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool {
1808 if h, ok := t.(tHelper); ok {
1809 h.Helper()
1810 }
1811 var expectedJSONAsInterface, actualJSONAsInterface interface{}
1812
1813 if err := json.Unmarshal([]byte(expected), &expectedJSONAsInterface); err != nil {
1814 return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...)
1815 }
1816
1817 if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil {
1818 return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...)
1819 }
1820
1821 return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...)
1822}
1823
1824// YAMLEq asserts that two YAML strings are equivalent.
1825func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool {

Calls 4

FailFunction · 0.70
EqualFunction · 0.70
HelperMethod · 0.65
ErrorMethod · 0.45