Details
-
Bug
-
Resolution: Fixed
-
Critical - P2
-
None
-
None
Description
I am pulling entries from a collection, and converting each to JSON.
The JSON which is generated is not always "legal": the mongo go driver does not seem to escape quotes in value strings, so the generated JSON is not compliant.
This seems like a pretty serious bug - Am I doing anything wrong? Relevant code pasted below.
func streamMongoCursorAsJSONResponse(w http.ResponseWriter, cur mongo.Cursor) {
|
w.Header().Set("Content-Type", "application/json")
|
w.Write([]byte("["))
|
count := 0
|
for cur.Next(context.Background()) {
|
elem := bson.NewDocument()
|
err := cur.Decode(elem)
|
if err != nil {
|
continue
|
}
|
if count != 0 {
|
w.Write([]byte(",\n"))
|
}
|
w.Write([]byte(elem.ToExtJSON(false)))
|
count++
|
}
|
w.Write([]byte("]"))
|
}
|