toExtJSON does not escape double quotes in strings

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Critical - P2
    • 0.0.17
    • Affects Version/s: None
    • Component/s: JSON & ExtJSON
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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("]"))
      }
      

       

              Assignee:
              Unassigned
              Reporter:
              Gregoire Pean
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: