File tree 2 files changed +46
-0
lines changed
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!-- Please do not remove this part-->
2
+ ![ Star Badge] ( https://img.shields.io/static/v1?label=%F0%9F%8C%9F&message=If%20Useful&style=style=flat&color=BC4E99 )
3
+ ![ Open Source Love] ( https://badges.frapsoft.com/os/v1/open-source.svg?v=103 )
4
+
5
+ # CSV TO JSON
6
+
7
+ ## 🛠️ Description
8
+ <!-- Remove the below lines and add yours -->
9
+ This script helps to convert a csv file to a json file.
10
+
11
+ ## ⚙️ Languages or Frameworks Used
12
+ <!-- Remove the below lines and add yours -->
13
+ language used - python3.
14
+ Packages required - csv and json.
15
+ if not already installed use pip3 install csv and pip3 install json.
16
+ (If there are a lot of them, including a ` requirements.txt ` file will work better.)
17
+
18
+ ## 🌟 How to run
19
+ <!-- Remove the below lines and add yours -->
20
+ python3 csv_to_json.py.
21
+
22
+
23
+
24
+ ## 🤖 Author
25
+ <!-- Remove the below lines and add yours -->
26
+ Rajit Gupta.
Original file line number Diff line number Diff line change
1
+ import csv
2
+ import json
3
+
4
+ # Function to convert csv to json
5
+ def csv_to_json (file_name ):
6
+ with open (file_name , 'r' ) as csv_file :
7
+ csv_data = csv .DictReader (csv_file )
8
+ data_list = [row for row in csv_data ]
9
+ json_data = json .dumps (data_list , indent = 4 )
10
+
11
+ with open ('data.json' ,'w' ) as json_file :
12
+ json_file .write (json_data )
13
+
14
+ # main function
15
+ def main ():
16
+ file_name = input ()
17
+ csv_to_json (file_name )
18
+
19
+ if __name__ == '__main__' :
20
+ main ()
You can’t perform that action at this time.
0 commit comments