![]() |
VOOZH | about |
JSON (JavaScript Object Notation) is a popular way to store and exchange data especially used in web APIs and configuration files. Pandas provides tools to parse JSON data and convert it into structured DataFrames for analysis. In this guide we will explore various ways to read, manipulate and normalize JSON datasets in Pandas.
Before working with JSON data we need to import pandas. If you're fetching JSON from a web URL or API you'll also need requests.
To read a JSON file or URL in pandas we use the read_json function. In the below code path_or_buf is the file or web URL to the JSON file.
if you don't have JSON file then create a small DataFrame and see how to convert it to JSON using different orientations.
Output:
👁 Screenshot-2025-03-15-114204You can fetch JSON data from online sources using the requests library and then convert it to a DataFrame. In the below example it reads and prints JSON data from the specified API endpoint using the pandas library in Python.
Output:
👁 Screenshot-2025-03-15-115552Sometimes JSON data has layers like lists or dictionaries inside other dictionaries then it is called as Nested JSON. To turn deeply nested JSON into a table use json_normalize() from pandas making it easier to analyze or manipulate in a table format.
Output:
👁 Screenshot-2025-03-15-120649As you can see in above output it gives a readable table with columns like id , orchestra , season etc. Working with JSON can seem confusing at first especially when it's deeply nested. But with pandas and a little practice using json_normalize() you can turn messy JSON into clean and tabular data.