title: How to serialize data to a given file using ujson library in python
body: <p>I am using below code to generate json file.</p>
  
  <pre><code>f = open("test.txt", 'r')
  buffer = f.readlines()
  rec_cnt = 1
  with open("test.json", "w") as ujson_file:  
  for line in buffer:
      data_dict[rec_cnt] = {line}
      if rec_cnt == 100:
          ujson.dump(data_dict.values(), ujson_file)
          data_dict.clear()
  rec_cnt +=1
  f.close()
  ujson_file
  </code></pre>
  
  <p>The issue is whenever I do it by batch, each batch of records are enclosed with [], which is forming an invalid json file.</p>
  
  <p>for example
  Input file will be</p>
  
  <pre><code> fruits      Orange       Apple        Kiwi        Banana     Veggies     Tomato       Potatoe      Carrot      Peas       Bigfruits   WaterMelon   cantaloupes  Papaya      melon      
  </code></pre>
  
  <p>output file should be:</p>
  
  <pre><code>[{Key:fruits, Values: [Orange, Apple, Kiwi, Banana]}][{Key:Veggies, Values: [Tomato, Potatoe, Carrot, Peas]}][{Key:Bigfruits, Values: [WaterMelon, cantaloupes, Papaya, melon]}]
  </code></pre>
  
  <p>Any suggestions of serializing the data with only one '[]' or without '[]'</p>