Skip to content

Commit 40aab32

Browse files
committed
updated
1 parent 0131608 commit 40aab32

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Scripts/Miscellaneous/JSONtoExcel/JSONtoEXCEL.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
# Importing Pandas and json
66
import json
7-
import pandas as pd
7+
from pandas import DataFrame
8+
import os
89
# Importing the data from a file using the load method
9-
with open('./sampleData.json') as json_file:
10-
data = json.load(json_file)
11-
# Creating a dataframe
12-
df = pd.DataFrame(data)
13-
df.to_excel('./exported_json_data.xlsx')
10+
def convert(inp_json_file:str) -> None:
11+
"""Simple function to convert any .json file to a xlsx file of any name"""
12+
with open(inp_json_file) as json_file:
13+
data = json.load(json_file)
14+
# Creating a dataframe
15+
df = DataFrame(data)
16+
out_xlsx_file = inp_json_file[:-4] + 'xlsx'
17+
df.to_excel(out_xlsx_file)
18+
19+
if __name__ == "__main__":
20+
convert(os.path.join((os.path.abspath(".")),"Python_and_the_web\Scripts\Miscellaneous\JSONtoExcel\sampleData.json"))

0 commit comments

Comments
 (0)