title: Increased Records while reading tar file with JSON formatted Data
body: <p>20190528.tar.gz file has 144,390 files and 22,673,735 records. Each file has some thousands JSON formatted data. </p>
  
  <p><strong>One Raw Record in single line [I've structured this to understand better]:</strong></p>
  
  <pre><code>{
      "t_id":"80740185.1558980000000.120184.121164",
      "s_id":"80740185",
      "pt_slot":"null:null",
      "ch_id":1,"o_id":121164,"c_id":120184,
      "msg_type":1,
      "amd":"{
                  \"msg\":\" some Bengali text\",
                  \"mask\":\"1GB_OFFER\",
                  \"ec\":\"1\",
                  \"time-out\":\"0\",
                  \"validity\":\"30052019 000000\"
             }",
      "time":1558960217731,
      "dlr":"1",
      "msisdn":"xxxxx",
      "entity":1
  }
  </code></pre>
  
  <p>I'm reading the tar.gz file and trying to make pipe separated CSV Files. </p>
  
  <p><strong>Here Is My Code</strong></p>
  
  <pre><code>#!/usr/bin/python
  import json
  import csv
  import ast
  import tarfile
  
  def write_sms_dat_to_csv_file():
          tar= tarfile.open('20190528.tar.gz','r:gz')
          csv_writer = csv.writer(open('csv_data.txt','wb+'),delimiter = '|')
          for member in tar.getmembers():
                  f = tar.extractfile(member)
                  if f is not None:
                          data = []
                          for line in f.readlines():
                                  print(line.strip())
                                  data.append(json.loads(line.strip()))
                                  for dt in data:
                                          csv_writer.writerow([dt['c_id'],dt['msisdn'],ast.literal_eval(dt['amd'])['mask'],ast.literal_eval(dt['amd'])['ec']])
  
  if __name__=="__main__":
          write_sms_dat_to_csv_file()
  </code></pre>
  
  <p>Above code has no issues, works fine. The problem is its creating the CSV file with more records than it should.  I mean much more records. Code is not finishing even the output records reached 30 million. I had to kill. </p>
  
  <p>I mean output record number should be same as input record number. </p>
  
  <p>I'm failing to find the bug in my code for which record is being duplicated.</p>
  
  <p>Could you help to find the error in logic? Thanks. </p>