I tried to convert json file into excel but somehow panda is not able to do it for all the keys.
I have a json input:
{
"result": [
{
"level": "L3_SW",
"name": "L23",
"type": "CM"
},
{
"level": "L3_SW",
"name": "SOFT",
"type": "QM"
}],
"context": {
"config": {
"project_area_name": "XYZ",
"component_name": "Configuration",
"config_name": "_WorkOn",
"bu": "H"
},
"meta": {
"project": {
"name": "_WorkOn",
"key": "2023-05-02_96614cc50ac8dc7e121f7090",
"started_at": "2023-05-02-16-00"
},
"task": {
"started": "2023-05-02-16-00",
"finished": "2023-05-02-16-00",
"req_count": 1
}
}
}
}
This is just one of a json file and I don't know what will be the structure of other json inputs.
I tried with panda library with I guess it required specific key which I don't want.
json_file_path = filedialog.askopenfilename(title='Select a JSON file', filetypes=[('JSON files','*.json')])
# Load the JSON file into a pandas dataframe
data = json.load(open(json_file_path))
print(data)
df = pd.DataFrame(data["result"]) #=============> this giving me output of excel column only of result array.
# Ask the user to select a location to save the Excel file
excel_file_path = filedialog.asksaveasfilename(title='Save as Excel',defaultextension='.xlsx')
# Save the dataframe as an Excel file
df.to_excel(excel_file_path, index=False)
How can I convert entire json to excel irrespective of the json structure which can give me all columns of the keys ?