diff --git a/csv_to_json/README.md b/csv_to_json/README.md new file mode 100644 index 000000000..d2ddd3d98 --- /dev/null +++ b/csv_to_json/README.md @@ -0,0 +1,14 @@ +# Script to convert CSV -> JSON + +Script expect the user to pass CSV file and saves the JSON file at same dir + +## install requirements/dependencies: + +python -r requirements.txt + +## how to use: + +call the program using: +`python main.py ` // Replace the FILENAME with your csv filename + +example: `python main.py Book.csv` \ No newline at end of file diff --git a/csv_to_json/main.py b/csv_to_json/main.py new file mode 100644 index 000000000..e619b84f7 --- /dev/null +++ b/csv_to_json/main.py @@ -0,0 +1,15 @@ +import pandas as pd +import sys +import os + +args = sys.argv[1:] # get command line *args +assert args, "No file was provided; Provide a CSV filename" + + +isdir = os.path.isdir(args[-1]) +# If input is CSV file +if not isdir: + assert args[-1].endswith(".csv"), "Input file is not CSV" + data = pd.read_csv(args[-1]) # load CSV data as Pd object + data.to_json(args[-1][:-4] + ".json", orient='records') + del data diff --git a/csv_to_json/requirements.txt b/csv_to_json/requirements.txt new file mode 100644 index 000000000..5c6ce4d33 --- /dev/null +++ b/csv_to_json/requirements.txt @@ -0,0 +1 @@ +pandas==1.3.3