I have a CSV file that has the data -
Time,site_name,cell_name,RRC_attempts,rrc_succ_rate
2018-01-12T08:37:00-06:00,910536_ARPIN,910536-24,1,100.0
2018-01-12T08:37:00-06:00,910536_ARPIN,910536-34,0,0.0
2018-01-12T08:37:00-06:00,910536_ARPIN,910536-14,5,100.0
I am using the json module in python to convert this csv to json
import json
import csv
csvfile_ind = open("test.csv",'r')
reader_ind = csv.DictReader(csvfile_ind)
json_file_ind = open("test_json.json", 'w')
for row in reader_ind:
json_file_ind.write(json.dumps(row,sort_keys=False, indent=4, separators=(',', ': ')))
My current output is -
[
{
"Time": "2018-01-12T08:37:00-06:00",
"site_name": "910536_ARPIN",
"cell_name": "910536-24",
"RRC_attempts": "1",
"rrc_succ_rate": "100.0"
},
{
"Time": "2018-01-12T08:37:00-06:00",
"site_name": "910536_ARPIN",
"cell_name": "910536-34",
"RRC_attempts": "0",
"rrc_succ_rate": "0.0"
},
{
"Time": "2018-01-12T08:37:00-06:00",
"site_name": "910536_ARPIN",
"cell_name": "910536-14",
"RRC_attempts": "5",
"rrc_succ_rate": "100.0"
}
]
My desired output is -
[
{
"Time": "2018-01-12T08:37:00-06:00",
"site_name": "910536_ARPIN",
"cell_name": "910536-24",
"RRC_attempts": 1,
"rrc_succ_rate": 100
},
{
"Time": "2018-01-12T08:37:00-06:00",
"site_name": "910536_ARPIN",
"cell_name": "910536-34",
"RRC_attempts": 0,
"rrc_succ_rate": 0
},
{
"Time": "2018-01-12T08:37:00-06:00",
"site_name": "910536_ARPIN",
"cell_name": "910536-14",
"RRC_attempts": 5,
"rrc_succ_rate": 100
}
]
How can tell json to parse the numbers as int or float and not as strings ? Please advise. Note - while writing my CSV file I explicitly converted my values to int or float using int() or float().