0

I have 2 different arrays:

dataList = ['a_cout', 'b_count', 'c_count']
dataList1 = [15404, 21381, 3]

I am trying to merge them into a json object as Key-Value pair like :

'{
  "a_count" : 15401,
  "b_count" : 21381,
  "c_count" : 3
 }'

I am using json lib in Python 2.x

1 Answers1

3

You can get those lists into a dictionary with a comprehension, then jsonify the dictionary:

import json 
mydict = {k:v for k,v in zip(dataList,dataList1)}
jdict = json.dumps(mydict)
jeremy_rutman
  • 3,552
  • 4
  • 28
  • 47