diff options
author | Gabriel Russell <gabriel.russell@mongodb.com> | 2016-01-19 13:52:55 -0500 |
---|---|---|
committer | Gabriel Russell <gabriel.russell@mongodb.com> | 2016-01-19 16:59:29 -0500 |
commit | 314837d4ce1f8f800208e2a4af3bc6b422e492b5 (patch) | |
tree | e977d0ac4bc25e746eedbc40ca19b8c7eb2aea88 | |
parent | 4eacf7c3a051193816ca66ff21c1b8f4f47e4343 (diff) | |
download | mongo-314837d4ce1f8f800208e2a4af3bc6b422e492b5.tar.gz |
TOOLS-1039 marshal the keys of MarshalD
-rw-r--r-- | common/bsonutil/marshal_d.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/common/bsonutil/marshal_d.go b/common/bsonutil/marshal_d.go index e8b5c769561..e47eea9c220 100644 --- a/common/bsonutil/marshal_d.go +++ b/common/bsonutil/marshal_d.go @@ -19,12 +19,16 @@ func (md MarshalD) MarshalJSON() ([]byte, error) { var buff bytes.Buffer buff.WriteString("{") for i, item := range md { - key := fmt.Sprintf(`"%s":`, item.Name) + key, err := json.Marshal(item.Name) + if err != nil { + return nil, fmt.Errorf("cannot marshal key %v: %v", item.Name, err) + } val, err := json.Marshal(item.Value) if err != nil { - return nil, fmt.Errorf("cannot marshal %v: %v", item.Value, err) + return nil, fmt.Errorf("cannot marshal value %v: %v", item.Value, err) } - buff.WriteString(key) + buff.Write(key) + buff.WriteString(":") buff.Write(val) if i != len(md)-1 { buff.WriteString(",") |