Skip to content

Added CSV_to_JSON script #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CSV_to_JSON/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# CSV to JSON converter
A python script that converts the csv file into json

# Usage
Make sure you have python 3 or higher, that's it.

## Files
before<br/>
![before](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/before.jpg)<br/>

## CLI interface
![image](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/CLI.jpg)

## Files
After<br/>
![after](https://github.com/TechBoyy6/Python-scripts-collection/blob/master/CSV_to_JSON/img/after.jpg)

## Contact
<a href="https://twitter.com/MoiZ__2001?s=08">
<img align="left" alt="Moiz's Twitter" width="22px" src="https://seeklogo.com/images/T/twitter-2012-positive-logo-916EDF1309-seeklogo.com.png"/>
</a>
29 changes: 29 additions & 0 deletions CSV_to_JSON/csv_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import csv
import json

file_name = input("Provide the CSV filename without extension>> ")

with open(file_name + '.csv') as f:

reader = csv.reader(f, delimiter=',')

titles = []
temp_data = {}

for heading in reader:
titles = heading
break

i = 1

for row in reader:
current_row = "row{}".format(i)
temp_data['{}'.format(current_row)] = {}
for col in range(len(titles)):
temp_data[current_row][titles[col]] = row[col]
i += 1

with open(file_name + '.json', 'w') as f_j:
json.dump(temp_data, f_j, indent=4)

print("File converted successfully :)\n")
Binary file added CSV_to_JSON/img/CLI.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CSV_to_JSON/img/after.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added CSV_to_JSON/img/before.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ This is a collection of short Python scripts to solve and automate tasks and sim
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
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 |
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 |
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 |