# How to Load the Exercises Dataset in Python: 3 Methods from JSON

> Easily load the exercises dataset in Python using three methods. Learn to parse JSON with the json module or load into pandas DataFrames for quick analysis.

- Repository: [Hasan Emir Yıldırım/exercises-dataset](https://github.com/hasaneyldrm/exercises-dataset)
- Tags: how-to-guide
- Published: 2026-08-01

---

**To load the exercises dataset in Python, use the standard library's `json` module to parse [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json), or load it directly into a pandas DataFrame with `pd.read_json()`.**

The **hasaneyldrm/exercises-dataset** repository stores fitness exercise data in JSON format under the `data/` directory. Each record follows the structure defined in [`exercises.schema.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/exercises.schema.json), allowing you to treat entries as Python dictionaries or DataFrame rows. You can load the dataset using only built-in libraries, or opt for pandas when you need structured data analysis capabilities.

## Loading the Dataset with the Python Standard Library

The most lightweight approach uses Python's built-in `json` module to read [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json) into memory. This method requires no external dependencies and returns a list of dictionaries representing each exercise.

```python
import json
from pathlib import Path

# Path to the JSON file inside the repository

DATA_PATH = Path(__file__).parent / "data" / "exercises.json"

with DATA_PATH.open(encoding="utf-8") as f:
    exercises = json.load(f)

# `exercises` is now a list of dictionaries

print(f"Loaded {len(exercises)} exercises")
print(exercises[0])           # Show the first record

```

This snippet uses `pathlib.Path` to construct an absolute path relative to your script location, ensuring the code works regardless of your current working directory. The `encoding="utf-8"` parameter ensures proper handling of special characters in exercise descriptions.

## Loading the Exercises Dataset into a Pandas DataFrame

For data analysis workflows, convert the JSON array directly into a **pandas DataFrame** using `pd.read_json()`. This approach automatically flattens the JSON structure into columns and provides vectorized operations for filtering and transformation.

```python
import pandas as pd
from pathlib import Path

DATA_PATH = Path(__file__).parent / "data" / "exercises.json"

# pandas can read a JSON array directly

df = pd.read_json(DATA_PATH)

print(df.head())               # First few rows as a DataFrame

print(df.columns)              # Column names derived from the schema

```

According to the hasaneyldrm/exercises-dataset source code, `pd.read_json()` infers column types from the schema-defined fields in [`exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/exercises.json), making it ideal for exploratory data analysis without manual parsing.

## Validating the Dataset Structure with JSON Schema

Before processing, validate the loaded data against [`data/exercises.schema.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.schema.json) to ensure structural integrity. This requires the third-party `jsonschema` library, which checks that all entries conform to the expected format defined in the repository.

```python
import json
import jsonschema
from pathlib import Path

SCHEMA_PATH = Path(__file__).parent / "data" / "exercises.schema.json"
DATA_PATH   = Path(__file__).parent / "data" / "exercises.json"

with SCHEMA_PATH.open() as f:
    schema = json.load(f)

with DATA_PATH.open() as f:
    data = json.load(f)

# Raises jsonschema.ValidationError if the file does not conform

jsonschema.validate(instance=data, schema=schema)

print("Dataset is valid according to the schema.")

```

Validation catches missing required fields or type mismatches before they cause runtime errors in your analysis pipeline.

## Understanding the Dataset File Structure

The repository organizes data files under the root `data/` directory:

- **[`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json)** — The main dataset containing an array of exercise objects with metadata like name, muscle group, and difficulty level.
- **[`data/exercises.schema.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.schema.json)** — The JSON Schema definition that specifies required fields, data types, and validation rules for each exercise entry.

Both files use UTF-8 encoding and follow standard JSON formatting, making them compatible with any JSON-compliant parser.

## Summary

- **Use `json.load()`** for zero-dependency loading from [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json) when you need raw Python dictionaries.
- **Use `pandas.read_json()`** to load the exercises dataset into a DataFrame for analytical workflows and columnar operations.
- **Validate with `jsonschema`** against [`data/exercises.schema.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.schema.json) to ensure data integrity before processing.
- **Construct paths with `pathlib.Path`** and `Path(__file__).parent` to maintain portable code across different working directories.

## Frequently Asked Questions

### Where is the exercises dataset stored in the repository?

The dataset is located at [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json) in the repository root, with its schema definition located at [`data/exercises.schema.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.schema.json). These paths are relative to the repository's main directory as implemented in hasaneyldrm/exercises-dataset.

### Do I need to install pandas to load the exercises dataset?

No. You can load the exercises dataset using only Python's built-in `json` module. Pandas is optional but recommended when you need to perform data analysis, filtering, or statistical operations on the exercise metadata.

### How do I handle file paths when loading the dataset in a different working directory?

Use `pathlib.Path(__file__).parent` to build absolute paths relative to your script's location. This approach ensures that [`data/exercises.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.json) resolves correctly regardless of where you execute the Python script from.

### Can I validate the dataset structure before processing it?

Yes. Install the `jsonschema` library and validate the loaded data against [`data/exercises.schema.json`](https://github.com/hasaneyldrm/exercises-dataset/blob/main/data/exercises.schema.json) using `jsonschema.validate()`. This checks that all entries contain required fields like exercise names and muscle groups, and that data types match the schema specifications.