How to Load and Parse the Exercises JSON Efficiently in Python

Use Python's standard json module for simple workloads, or switch to orjson for 2-3× faster parsing when loading the 1,324 exercise records from data/exercises.json in the hasaneyldrm/exercises-dataset repository.

The hasaneyldrm/exercises-dataset repository provides a structured fitness dataset containing multilingual exercise instructions, media references, and attribution data stored in data/exercises.json. Because this file contains a modestly-sized JSON array of 1,324 objects, you can efficiently load and parse the exercises JSON using techniques ranging from standard library approaches to high-performance third-party libraries depending on your specific memory and speed constraints.

Load the Exercises JSON with the Standard Library

For most applications, Python's built-in json module provides sufficient performance and requires no external dependencies. The repository's README.md demonstrates this pattern at lines 310 and 349.

Open the file with explicit UTF-8 encoding and parse the entire array into a Python list:

import json

with open("data/exercises.json", "r", encoding="utf-8") as f:
    exercises = json.load(f)

This approach loads all 1,324 exercise objects into memory as a list of dictionaries, which is efficient enough for typical data analysis tasks.

High-Performance Parsing Techniques

When processing the dataset repeatedly or under strict memory constraints, consider these optimized approaches to load and parse the exercises JSON.

Accelerate Parsing with orjson

The third-party orjson library uses Rust-based optimizations to achieve 2-3× faster parsing than the standard library. It also produces bytes-based output suitable for direct disk writes.

import orjson
import pathlib

exercises = orjson.loads(pathlib.Path("data/exercises.json").read_bytes())

Memory-Mapped File Access

For larger files or to eliminate extra memory copies, combine mmap with orjson. This technique maps the file directly into virtual memory without loading it through Python's buffer protocol.

import orjson
import mmap
import pathlib

with pathlib.Path("data/exercises.json").open('rb') as f:
    with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm:
        exercises = orjson.loads(mm)

Stream Records with ijson

When working with memory-constrained environments or processing only a subset of records, use ijson to parse the JSON incrementally. This yields one exercise object at a time without loading the entire file into RAM.

import ijson

with open("data/exercises.json", "r", encoding="utf-8") as f:
    for exercise in ijson.items(f, "item"):
        # Process each exercise dictionary individually

        print(exercise["name"]["en"])

Validate Against the JSON Schema

The repository includes data/exercises.schema.json to enforce structural correctness. Use jsonschema to validate the dataset after loading or during streaming to ensure every record conforms to the expected format.

import json
import jsonschema

schema = json.load(open("data/exercises.schema.json"))
exercises = json.load(open("data/exercises.json", encoding="utf-8"))

jsonschema.validate(exercises, schema)

Validation guarantees that required fields like multilingual names and media references exist before your application processes the data.

Best Practices for Production Workloads

Follow these guidelines when integrating the exercises dataset into production pipelines:

  • Read once, cache often: Parse data/exercises.json using orjson or the standard library, then cache the resulting objects using pickle or msgpack if accessed repeatedly in the same session.
  • Validate at boundaries: Always validate against data/exercises.schema.json when ingesting data from external sources or after transformations.
  • Choose streaming for scale: Switch to ijson streaming when the dataset grows beyond available memory or when processing individual records independently.

Summary

  • The standard library json module efficiently handles the 1,324 records in data/exercises.json for most use cases.
  • orjson delivers 2-3× faster parsing and works seamlessly with memory-mapped files via mmap for optimal memory usage.
  • ijson enables streaming parsing to process exercises one-by-one without loading the entire array into RAM.
  • Validate all data against data/exercises.schema.json using jsonschema to ensure structural integrity.
  • Cache parsed objects between operations to avoid redundant disk I/O in production environments.

Frequently Asked Questions

What is the fastest way to load the exercises JSON in Python?

orjson provides the fastest parsing method, delivering 2-3× better performance than the standard library json module when loading the 1,324 exercise records from data/exercises.json. For maximum efficiency, read the file bytes using pathlib.Path.read_bytes() and pass them to orjson.loads().

How do I validate the exercises data against the provided schema?

Import jsonschema alongside the standard json module, load the schema from data/exercises.schema.json, and call jsonschema.validate(exercises, schema) after parsing. This ensures every exercise object contains required fields like multilingual names and proper media references.

Can I process the exercises file without loading it all into memory?

Yes, use the ijson library to stream the JSON array incrementally. Open data/exercises.json in text mode and use ijson.items(f, "item") to yield one exercise dictionary at a time, keeping memory footprint constant regardless of file size.

Where are the basic loading examples documented in the repository?

The README.md file in hasaneyldrm/exercises-dataset contains usage snippets demonstrating the standard open() and json.load() pattern. These examples appear at lines 310 and 349, providing the reference implementation for basic loading tasks.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →