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 7b3f102

Browse files
Merge pull request avinashkranjan#1693 from sagnik-p/json-to-csv
added json-to-csv.py
2 parents 6abfb19 + 6ce2deb commit 7b3f102

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-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)

‎JSON-to-CSV/readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# JSON to CSV
2+
3+
This python script converts a JSON file to CSV file
4+
5+
Data stored in json format is used for transferring data
6+
Data in csv format is mostly used for storing / reading data
7+
This script converts the .json file to .csv file
8+
9+
10+
The default output is 'output.csv'
11+
>the file path and name can be changed

0 commit comments

Comments
(0)

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