hi i want to create a json file but when I print the result the result is complete but when I save in a file .json the file only save the last key of the data
import json
import csv
jsonFile = r'Prueba.json'
with open('file1.csv', newline='') as csvfile:
datos = csv.DictReader(csvfile)
for row in datos:
datos_jason = json.dumps(row, indent=4, skipkeys = True)
print(datos_jason)
with open(jsonFile, 'w', encoding='utf-8') as jsonf:
jsonf.write(json.dumps(row, indent=4))
in the terminal
{
"companyemail": "user 1",
"password": "12345",
"firstname": "Don10",
"lastname": "Api10"
}
{
"companyemail": "user 2",
"password": "12345",
"firstname": "Don11",
"lastname": "Api11"
}
{
"companyemail": "user 3",
"password": "12345",
"firstname": "Don12",
"lastname": "Api12"
}
{
"companyemail": "user 4",
"password": "12345",
"firstname": "Don13",
"lastname": "Api13"
}
{
"companyemail": "user 5",
"password": "12345",
"firstname": "Don14",
"lastname": "Api14"
}
but in the json file
{
"companyemail": "user 5",
"password": "12345",
"firstname": "Don14",
"lastname": "Api14"
}
In the file only save the last users
I add the csv file
companyemail,password,firstname,lastname
user 1,12345,Don10,Api10
user 2,12345,Don11,Api11
user 3,12345,Don12,Api12
user 4,12345,Don13,Api13
user 5,12345,Don14,Api14
I'm new in programming and I want to push this json format to a POST with API, those part work ok but only upload the last user