RE: Best way to convert API JSON response to Excel in Python?

A simple way is to fetch the API response as JSON and convert it to a DataFrame, then export it to Excel.

import requests
import pandas as pd

url = "https://api.example.com/data"
response = requests.get(url)

data = response.json()

df = pd.json_normalize(data)
df.to_excel("output.xlsx", index=False)

requests gets the API data, pandas converts the JSON into a structured table, and to_excel() saves it as an Excel file. This works well when the JSON response is fairly structured.

Be the first to post a comment.

Add a comment