Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Development #13

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions projects/Convert_JSON_to_CSV/converter.py
Original file line number Diff line number Diff line change
@@ -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)}')
12 changes: 12 additions & 0 deletions projects/Convert_JSON_to_CSV/input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"Name": "Akash",
"age": 26,
"birthyear": "1994"
},
{
"Name": "Abhay",
"age": 34,
"birthyear": "1986"
}
]
3 changes: 3 additions & 0 deletions projects/Convert_JSON_to_CSV/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Name,age,birthyear
Akash,26,1994
Abhay,34,1986