Tracy Chen
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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Tracy Chen
Tracy Chen

Written by Tracy Chen

A product person who still dabbles in code.

No responses yet

Write a response