The default behavior when JSON marshalling a bson.Raw field doesn't print the data represented by the bson.Raw field cleanly. Can a MarshalJSON method be added to bson.Raw which would allow the JSON marshaller to cleanly print a value in bson.Raw?
Current:
{
"Kind": 4,
"Data": "{something}"
}
Suggested:
{
"field": "value"
},
Example MarshalJSON:
// MarshalJSON serializes raw bson into JSON
func (raw Raw) MarshalJSON() ([]byte, error) {
var rawInterface interface{}
err := raw.Unmarshal(&rawInterface)
if err != nil {
return nil, errors.New("unable to unmarshal BSON data into interface")
}
return json.Marshal(rawInterface)
}
The default behavior when JSON marshalling a
bson.Raw
field doesn't print the data represented by thebson.Raw
field cleanly. Can aMarshalJSON
method be added tobson.Raw
which would allow the JSON marshaller to cleanly print a value in bson.Raw?Current:
Suggested:
Example MarshalJSON: