Convert JSON to CSV

This commit is contained in:
2024-05-10 22:19:42 +03:00
parent d0d99f69c5
commit c69d01b5bd
4 changed files with 36 additions and 1 deletions

15
converter.py Normal file
View File

@@ -0,0 +1,15 @@
import json
if __name__ == '__main__':
try:
with open('input.json', 'r') as f:
data = json.loads(f.read())
output = ','.join([*data[0]])
for obj in data:
output += f'\n{obj["Name"]},{obj["age"]},{obj["birthyear"]}'
with open('output.csv', 'w') as f:
f.write(output)
except Exception as ex:
print(f'Error: {str(ex)}')