I want the below JSON output after parsing csv string in Python to feed API:
{
"_records":[
{
"_fields":{
"Account":"DSP2",
"Code":"11"
}
},
{
"_fields":{
"Account":"DSP1",
"Code":"11"
}
}
]
}
Since I am new to python after some research I was able to write the below code, which is working, but I am getting some additional junk characters in the final output.
Output :
{'records': [{'{"fields": {"Account": "T671", "Code": "A7710"}}'},
enter code here
"T672", "Code": "A7799"}}'}]}
can someone help on how to get rid of extra {' and '}?
Code -
data = {'records': []}
data1 = {}
line_var = input_var_1.splitlines()
for line in line_var:
records = line.split(',')
data1.update({'fields': {'Account': records[0].strip(),'Code': records[1].strip()}})
data2 = json.dumps(data1)
data["records"].append({data2})