How to Validate the Exercises Dataset Using JSON Schema: A Complete Guide
Validate exercise records against the formal JSON Schema in data/exercises.schema.json using any Draft 2020-12 compliant validator to catch type mismatches, missing language keys, and malformed URLs before processing.
The hasaneyldrm/exercises-dataset repository maintains a structured collection of fitness exercises as JSON objects. To ensure data integrity across 1,324+ records, the repository ships a formal JSON Schema that defines every field, required property, and constraint. Validating the exercises dataset using JSON Schema guarantees that your application receives correctly typed multilingual content, valid media URLs, and complete metadata before ingestion.
Understanding the JSON Schema Structure
The schema file data/exercises.schema.json follows the Draft 2020-12 specification and serves as the strict contract for every exercise object stored in data/exercises.json.
Schema Location and Specification
- Schema Path:
data/exercises.schema.json - Data File:
data/exercises.json - Specification: Draft 2020-12 (modern JSON Schema version supporting strict type checking and advanced string formats)
Field Definitions and Constraints
The schema enforces specific data types and constraints for each exercise record:
id: String representing a numeric identifiername,category,body_part,equipment,muscle_group,target,media_id,image,gif_url,attribution: String values, with media fields requiring valid URI formatsinstructions: Object containing exactly nine required language keys (en,es,it,tr,ru,zh,hi,pl,ko), each holding a string instruction blockinstruction_steps: Object where each language entry is an array of strings representing step-by-step instructionssecondary_muscles: Array of strings listing secondary muscle groupscreated_at: ISO-8601 date-time string (format: date-time)
Validating with Python
Use the jsonschema library to validate the dataset programmatically. This approach catches missing required fields and type violations for each exercise record.
import json
from jsonschema import validate, ValidationError
# Load the schema
with open("data/exercises.schema.json", "r", encoding="utf-8") as f:
schema = json.load(f)
# Load the dataset (or any custom JSON)
with open("data/exercises.json", "r", encoding="utf-8") as f:
exercises = json.load(f)
# Validate each record
errors = []
for idx, ex in enumerate(exercises, start=1):
try:
validate(instance=ex, schema=schema)
except ValidationError as e:
errors.append(f"Exercise #{idx} ({ex.get('id')}): {e.message}")
if errors:
print("Validation failed:")
for err in errors:
print(err)
else:
print("All exercises validated successfully")
Validating with Node.js
For JavaScript environments, AJV (Another JSON Schema Validator) provides high-performance validation with detailed error reporting.
const Ajv = require("ajv");
const fs = require("fs");
// Load schema and data
const schema = JSON.parse(fs.readFileSync("data/exercises.schema.json", "utf-8"));
const exercises = JSON.parse(fs.readFileSync("data/exercises.json", "utf-8"));
const ajv = new Ajv({ allErrors: true });
const validate = ajv.compile(schema);
let hasError = false;
exercises.forEach((ex, i) => {
const valid = validate(ex);
if (!valid) {
hasError = true;
console.error(`Exercise #${i + 1} (id=${ex.id}) validation errors:`);
console.error(validate.errors);
}
});
if (!hasError) console.log("All exercises passed AJV validation");
Command-Line Validation
Use ajv-cli for quick validation without writing custom code. This method is ideal for CI/CD pipelines or pre-commit hooks.
# Install globally (once)
npm i -g ajv-cli
# Validate the whole dataset
ajv validate -s data/exercises.schema.json -d data/exercises.json
Validating with Go
For Go applications, the github.com/santhosh-tekuri/jsonschema/v5 library compiles the schema and validates individual records against the Draft 2020-12 specification.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"github.com/santhosh-tekuri/jsonschema/v5"
)
func main() {
// Compile the schema
compiler := jsonschema.NewCompiler()
if err := compiler.AddResource("schema.json",
// Load from file
// (you could also embed the schema)
); err != nil {
log.Fatal(err)
}
schema, err := compiler.Compile("schema.json")
if err != nil {
log.Fatal(err)
}
// Load the dataset
data, _ := ioutil.ReadFile("data/exercises.json")
var exercises []interface{}
if err := json.Unmarshal(data, &exercises); err != nil {
log.Fatal(err)
}
// Validate each entry
for i, ex := range exercises {
if err := schema.Validate(ex); err != nil {
fmt.Printf("Exercise #%d validation error: %v\n", i+1, err)
}
}
}
Summary
- Locate the authoritative schema at
data/exercises.schema.json(Draft 2020-12) in the hasaneyldrm/exercises-dataset repository - Validate
data/exercises.jsonagainst constraints governing 12+ string fields, multilingual instruction objects, and media URIs - Use Python's
jsonschema, Node'sAJV, or Go'sjsonschema/v5libraries for programmatic validation - Execute
ajv-clifor rapid command-line validation during development workflows - Catch missing language keys, malformed ISO-8601 dates, invalid URIs, and type errors before runtime
Frequently Asked Questions
What JSON Schema draft does the exercises dataset use?
The schema conforms to Draft 2020-12, as specified in the $schema property within data/exercises.schema.json. This modern draft supports strict type checking, advanced string formats like date-time and uri, and robust validation of nested multilingual objects.
Which fields are required for a valid exercise record?
According to the schema definition, every exercise must include id, name, category, body_part, equipment, muscle_group, target, instructions (with all nine mandatory language keys), instruction_steps, media_id, image, gif_url, secondary_muscles, and created_at. Missing any of these properties triggers a validation error.
Can I validate a single exercise instead of the entire array?
Yes. Most validators accept individual objects. In Python, pass a single dictionary to validate() instead of iterating the full list. In AJV, compile the schema once and invoke the returned validation function on a single exercise object extracted from the array.
What common errors does the schema catch during validation?
The schema validates that instructions contains exactly the required language keys (en, es, it, tr, ru, zh, hi, pl, ko), that created_at matches ISO-8601 format, that media URLs conform to URI syntax, and that secondary_muscles is strictly an array of strings rather than a single comma-separated value.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →