diff --git a/Scripts/Miscellaneous/JSONtoExcel/JSONtoEXCEL.py b/Scripts/Miscellaneous/JSONtoExcel/JSONtoEXCEL.py index 2e0654cb0..f48248a19 100644 --- a/Scripts/Miscellaneous/JSONtoExcel/JSONtoEXCEL.py +++ b/Scripts/Miscellaneous/JSONtoExcel/JSONtoEXCEL.py @@ -4,10 +4,17 @@ # Importing Pandas and json import json -import pandas as pd +from pandas import DataFrame +import os # Importing the data from a file using the load method -with open('./sampleData.json') as json_file: - data = json.load(json_file) -# Creating a dataframe -df = pd.DataFrame(data) -df.to_excel('./exported_json_data.xlsx') \ No newline at end of file +def convert(inp_json_file:str) -> None: + """Simple function to convert any .json file to a xlsx file of any name""" + with open(inp_json_file) as json_file: + data = json.load(json_file) + # Creating a dataframe + df = DataFrame(data) + out_xlsx_file = inp_json_file[:-4] + 'xlsx' + df.to_excel(out_xlsx_file) + +if __name__ == "__main__": + convert(os.path.join((os.path.abspath(".")),"Python_and_the_web\Scripts\Miscellaneous\JSONtoExcel\sampleData.json"))