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

Commit bb49d8d

Browse files
committed
Convert JSON to CSV
1 parent ff78e75 commit bb49d8d

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import json
2+
3+
if __name__ == '__main__':
4+
try:
5+
with open('input.json', 'r') as f:
6+
data = json.loads(f.read())
7+
8+
output = ','.join([*data[0]])
9+
for obj in data:
10+
output += f'\n{obj["Name"]},{obj["age"]},{obj["birthyear"]}'
11+
12+
with open('output.csv', 'w') as f:
13+
f.write(output)
14+
except Exception as ex:
15+
print(f'Error: {str(ex)}')
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"Name": "Akash",
4+
"age": 26,
5+
"birthyear": "1994"
6+
},
7+
{
8+
"Name": "Abhay",
9+
"age": 34,
10+
"birthyear": "1986"
11+
}
12+
]
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Name,age,birthyear
2+
Akash,26,1994
3+
Abhay,34,1986

0 commit comments

Comments
 (0)