diff --git a/binding/json.go b/binding/json.go index aa7039d3..20aae8cf 100644 --- a/binding/json.go +++ b/binding/json.go @@ -7,9 +7,11 @@ package binding import ( "net/http" - json "github.com/json-iterator/go" + "github.com/json-iterator/go" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + type jsonBinding struct{} func (jsonBinding) Name() string { diff --git a/context_test.go b/context_test.go index 6c4af42f..f57fa6fd 100644 --- a/context_test.go +++ b/context_test.go @@ -582,7 +582,7 @@ func TestContextRenderIndentedJSON(t *testing.T) { c.IndentedJSON(201, H{"foo": "bar", "bar": "foo", "nested": H{"foo": "bar"}}) assert.Equal(t, w.Code, 201) - assert.Equal(t, "{\n \"foo\":\"bar\",\n \"bar\":\"foo\",\n \"nested\":{\n \"foo\":\"bar\"\n }\n}", w.Body.String()) + assert.Equal(t, "{\n \"bar\":\"foo\",\n \"foo\":\"bar\",\n \"nested\":{\n \"foo\":\"bar\"\n }\n}", w.Body.String()) assert.Equal(t, "application/json; charset=utf-8", w.HeaderMap.Get("Content-Type")) } diff --git a/errors.go b/errors.go index 19b2cfbe..26d4e474 100644 --- a/errors.go +++ b/errors.go @@ -9,9 +9,11 @@ import ( "fmt" "reflect" - json "github.com/json-iterator/go" + "github.com/json-iterator/go" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + type ErrorType uint64 const ( diff --git a/errors_test.go b/errors_test.go index 778ecf0a..a0d95504 100644 --- a/errors_test.go +++ b/errors_test.go @@ -8,7 +8,6 @@ import ( "errors" "testing" - json "github.com/json-iterator/go" "github.com/stretchr/testify/assert" ) @@ -32,7 +31,7 @@ func TestError(t *testing.T) { }) jsonBytes, _ := json.Marshal(err) - assert.Equal(t, "{\"meta\":\"some data\",\"error\":\"test error\"}", string(jsonBytes)) + assert.Equal(t, "{\"error\":\"test error\",\"meta\":\"some data\"}", string(jsonBytes)) err.SetMeta(H{ "status": "200", @@ -91,7 +90,7 @@ Error #03: third H{"error": "third", "status": "400"}, }) jsonBytes, _ := json.Marshal(errs) - assert.Equal(t, "[{\"error\":\"first\"},{\"meta\":\"some data\",\"error\":\"second\"},{\"status\":\"400\",\"error\":\"third\"}]", string(jsonBytes)) + assert.Equal(t, "[{\"error\":\"first\"},{\"error\":\"second\",\"meta\":\"some data\"},{\"error\":\"third\",\"status\":\"400\"}]", string(jsonBytes)) errs = errorMsgs{ {Err: errors.New("first"), Type: ErrorTypePrivate}, } diff --git a/render/json.go b/render/json.go index 38967409..17e6ac86 100644 --- a/render/json.go +++ b/render/json.go @@ -8,9 +8,11 @@ import ( "bytes" "net/http" - json "github.com/json-iterator/go" + "github.com/json-iterator/go" ) +var json = jsoniter.ConfigCompatibleWithStandardLibrary + type JSON struct { Data interface{} }