Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b20afcb

Browse files
committed
added json-to-csv.py
1 parent cbe16aa commit b20afcb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎JSON-to-CSV/json-to-csv.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## json and csv modules are installed by default, no need to install
2+
3+
import json
4+
import csv
5+
6+
7+
## specify file path , along with extension
8+
input_json_file='input.json'
9+
csv_file = 'output.csv'
10+
11+
# Load JSON data from a file
12+
with open(input_json_file) as json_file:
13+
data = json.load(json_file)
14+
15+
# Open the CSV file in write mode
16+
with open(csv_file, 'w', newline='') as csvfile:
17+
# Create a CSV writer
18+
writer = csv.writer(csvfile)
19+
20+
# Write the header row based on the keys of the first JSON object
21+
writer.writerow(data[0].keys())
22+
23+
# Write the data rows
24+
for item in data:
25+
writer.writerow(item.values())
26+
27+
printf("Conversion successfull. The output file is saved as : "+ csv_file)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /