Skip to content

Commit a3aaa53

Browse files
committed
Modify not to add "error" key; only marshal the list.
1 parent b92f908 commit a3aaa53

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

multierror.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,21 @@ func (e *Error) GoString() string {
4343
// MarshalJSON returns a valid json representation of a multierror,
4444
// as an object with an array of error strings.
4545
func (e *Error) MarshalJSON() ([]byte, error) {
46-
j := map[string][]string{
47-
"errors": []string{},
48-
}
46+
j := []string{}
4947
for _, err := range e.Errors {
50-
j["errors"] = append(j["errors"], err.Error())
48+
j = append(j, err.Error())
5149
}
5250
return json.Marshal(j)
5351
}
5452

5553
// UnmarshalJSON from an array of strings.
5654
func (e *Error) UnmarshalJSON(b []byte) error {
57-
j := make(map[string][]string)
55+
j := []string{}
5856
if err := json.Unmarshal(b, &j); err != nil {
5957
return err
6058
}
61-
if j["errors"] != nil {
62-
for _, msg := range j["errors"] {
59+
if j != nil {
60+
for _, msg := range j {
6361
e.Errors = append(e.Errors, fmt.Errorf(msg))
6462
}
6563
}

multierror_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestError_json(t *testing.T) {
5555
if err != nil {
5656
t.Fatalf("unexpected error; got %#v", err)
5757
}
58-
j := `{"errors":["foo","bar"]}`
58+
j := `["foo","bar"]`
5959
if string(b) != j {
6060
t.Errorf("bad representation; got: %s, want: %s", string(b), j)
6161
}

0 commit comments

Comments
 (0)