Skip to content

Commit ed98cea

Browse files
committed
Modify not to add "error" key; only marshal the list.
1 parent 738fe9d commit ed98cea

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
@@ -44,23 +44,21 @@ func (e *Error) GoString() string {
4444
// MarshalJSON returns a valid json representation of a multierror,
4545
// as an object with an array of error strings.
4646
func (e *Error) MarshalJSON() ([]byte, error) {
47-
j := map[string][]string{
48-
"errors": []string{},
49-
}
47+
j := []string{}
5048
for _, err := range e.Errors {
51-
j["errors"] = append(j["errors"], err.Error())
49+
j = append(j, err.Error())
5250
}
5351
return json.Marshal(j)
5452
}
5553

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

multierror_test.go

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

0 commit comments

Comments
 (0)