Skip to content

Commit 57bfd73

Browse files
authored
Merge pull request #79 from TechBoyy6/master
Added CSV_to_JSON script
2 parents e34ea58 + a774c88 commit 57bfd73

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

CSV_to_JSON/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CSV to JSON converter
2+
A python script that converts the csv file into json
3+
4+
# Usage
5+
Make sure you have python 3 or higher, that's it.
6+
7+
## Files
8+
before<br/>
9+
![before](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/before.jpg)<br/>
10+
11+
## CLI interface
12+
![image](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/CLI.jpg)
13+
14+
## Files
15+
After<br/>
16+
![after](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/after.jpg)
17+
18+
## Contact
19+
<a href="https://twitter.com/MoiZ__2001?s=08">
20+
<img align="left" alt="Moiz's Twitter" width="22px" src="https://seeklogo.com/images/T/twitter-2012-positive-logo-916EDF1309-seeklogo.com.png"/>
21+
</a>

CSV_to_JSON/csv_to_json.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import csv
2+
import json
3+
4+
file_name = input("Provide the CSV filename without extension>> ")
5+
6+
with open(file_name + '.csv') as f:
7+
8+
reader = csv.reader(f, delimiter=',')
9+
10+
titles = []
11+
temp_data = {}
12+
13+
for heading in reader:
14+
titles = heading
15+
break
16+
17+
i = 1
18+
19+
for row in reader:
20+
current_row = "row{}".format(i)
21+
temp_data['{}'.format(current_row)] = {}
22+
for col in range(len(titles)):
23+
temp_data[current_row][titles[col]] = row[col]
24+
i += 1
25+
26+
with open(file_name + '.json', 'w') as f_j:
27+
json.dump(temp_data, f_j, indent=4)
28+
29+
print("File converted successfully :)\n")

CSV_to_JSON/img/CLI.jpg

13.7 KB
Loading

CSV_to_JSON/img/after.jpg

14.1 KB
Loading

CSV_to_JSON/img/before.jpg

12.5 KB
Loading

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ This is a collection of short Python scripts to solve and automate tasks and sim
5050
30 | [**EC2-Instance-Launcher**](https://github.com/DiptoChakrabarty/Useful-Python-scripts-collection/blob/master/EC2-launcher/ec2.py) | Python script to automatically launch ec2 instances in AWS | boto3 , botocore , python-dotenv , environmental variables
5151
31 | [**DirectorySummarizer**](https://github.com/j0fiN/Useful-Python-scripts-collection/blob/master/DirectorySummarizer/directory_summarizer.py) | A Python script which summarizes the number of different files in a directory. It also gives out the percentage of a particular file extension you want to know. | None |
5252
31 | [**Folder-Automater**](https://github.com/decipher07/Useful-Python-scripts-collection/blob/master/Folder-Automater/automateall.py) | A Python script which compiles all the different formats of files present in the respective folder to a new folder containing only the Specified files . | None |
53+
32 | [**CSV_to_JSON**](https://github.com/TechBoyy6/Python-scripts-collection/tree/master/CSV_to_JSON) | A script that converts the csv file into json file. | None |

0 commit comments

Comments
 (0)