title: How to get output in proper json format in this piece of code in python
body: <p>Am working on python and mongodb. I am trying to find names from a table with the by matching them with their phone no.s. The phone number is in a list which i created by getting the numbers from another table. Its working fine but I am getting the output being printed twice.</p>
  
  <pre><code>phone = ["9585507882","9542158582"]           
  datum = []
  for i in phone:
      cursor = db.name.find({"phone": i},{"_id": False})
      value = yield cursor.count()
      if value is 0:
          pass
      else:
          result = []
          for document in (yield cursor.to_list(length=100)):
              datum.append(document)
          print(datum)
          self.write(bson.json_util.dumps({"result": datum}))
  </code></pre>
  
  <p>My output is</p>
  
  <pre><code>{"result": [{"phone": "9585507882", "name": "Sanjay"}]}{"result": [{"phone": "9585509882", "name": "Sanjay"}, {"phone": "9542158582", "name": "Joe"}]}
  </code></pre>
  
  <p>can anyone help me out with this problem.</p>