Nov 1, 2023
Importing JSON Data into Excel with Python
If you ever find yourself needing to import JSON data from an API into Excel for additional data manipulation, look no further. Here is a quick Python script to save you some time:
import json
import pandas as pd
from pandas import json_normalize
# Replace with the actual path for your JSON file
with open('ENTER PATH FOR JSON FILE.json') as json_file:
data = json.load(json_file)
# Flatten the nested JSON structure
flattened_data = json_normalize(data)
# Create a DataFrame
df = pd.DataFrame(flattened_data)
# Write to Excel. Replace with the desired output Excel file path
df.to_excel('ENTER PATH TO OUTPUT EXCEL.xlsx')
Prerequisite/Installation
pip install pandas
pip install openpyxl