Hi @TopherGopher,
The reason this happens is because the driver unpacks BSON documents in to a bson.D object, which doesn’t support converting to/from JSON. The bson.D type is internally represented as a slice to structs with fields named Key and Value, so that explains why the JSON is structured that way. If you know that the user-provided value will always be a document, you can change your type to
type GlobalKeypair struct {
Key string
Value bson.M
}
Unlike bson.D, the bson.M type is simply map[string]interface{} so the standard library json functions can handle it. Can you let me know if this works for you? I’ve also opened https://jira.mongodb.org/browse/GODRIVER-1765 to make this actually work for bson.D as well.
– Divjot