[GODRIVER-627] How to convert bson.Document to valid JSON Created: 07/Nov/18  Updated: 11/Sep/19  Resolved: 03/Dec/18

Status: Closed
Project: Go Driver
Component/s: JSON & ExtJSON
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Lucas Pelegrino Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Guys

I did a .Find() and got back a bson.Document, how can I transform this into a valid JSON string?

I tried .ToExtJSON(false), but this doesn't produce valid JSON, since it doesn't quote new lines and tabs.

 

Thank you!



 Comments   
Comment by Ian Whalen (Inactive) [ 03/Dec/18 ]

Fixed as per Kris' comment above.

Comment by Kristofer Brandow (Inactive) [ 12/Nov/18 ]

Hi lucaswxp,

You can use the MarshalExtJSON function for this https://godoc.org/github.com/mongodb/mongo-go-driver/bson#MarshalExtJSON.

– Kris 

Comment by Lucas Pelegrino [ 08/Nov/18 ]

Hey guys.

This seems like a real basic essential issue, don't know if I should be something differently, but there's nothing on the examples on how to handle this.

Generated at Thu Feb 08 08:34:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.