title: Convert bson to json in python/pymongo
body: <p>I'm trying to convert bson data gotten straight from pymongo into json data. Is there a straight forward way to do this with python using pymongo or something else? </p>
  
  <p>Here's the code if it helps: </p>
  
  <pre><code>def email_main(request):
      collection = get_collection("nimbus").fullcontact_email_data
      if request.method == "POST":
          data = collection.save(dict(request.POST.iterlists()))
          response = HttpResponse(data, content_type="application/json")
      elif request.method == "GET":
          getParams = convertQuerydictToDict(request.GET)
          page, itemsPerPage = getPageDataFromDict(getParams)
          getParamsWithNoPageData = createDictWithoutPageData(getParams)
          data = collection.find(getParamsWithNoPageData)[page:page+itemsPerPage+1]
          response = HttpResponse(data, content_type="application/json")
      else:
          response = HttpResponse(status=404)
      return response
  
  
  def convertQuerydictToDict(queryDict):
      return dict(queryDict.iterlists())
  
  
  def getPageDataFromDict(myDict):
      if "page" in myDict and "itemsPerPage" in myDict:
          page, itemsPerPage = myDict["page"], myDict['itemsPerPage']
      elif "page" in myDict:
          page, itemsPerPage = myDict["page"], 10
      else:
          page, itemsPerPage = 0, 10
      return page, itemsPerPage
  
  def createDictWithoutPageData(myDict):
      newDict = deepcopy(myDict)
      newDict.pop("page", None)
      newDict.pop("itemsPerPage", None)
      return newDict
  </code></pre>
  
  <p>basically that data variable needs to get turned into proper json. There must be some built in thing that does this.  </p>
  
  <p>For clarity here's what I get when I put data into the python console:</p>
  
  <pre><code>&gt;&gt;&gt; data
  &lt;pymongo.cursor.Cursor object at 0x4dd0f50&gt;
  &gt;&gt;&gt; data[0]
  {u'blah': u'go', u'_id': ObjectId('540e3fd8bb6933764d5650b7')}
  </code></pre>
  
  <p>ObjectId is not part of the json spec...</p>