Cron Expression Parser API: The Complete Guide

Need to parse cron expressions in your application? This guide covers everything you need to know about cron expression parsing via API, including cron syntax, validation, human-readable descriptions, and implementation examples in multiple languages.

What is a Cron Expression?

A cron expression is a string consisting of five or six fields that describe individual details of a schedule. Cron expressions are used in Unix-like operating systems to schedule jobs, and they're widely adopted in web applications for task scheduling.

A typical cron expression looks like this: 0 9 * * 1-5 (runs at 9 AM on weekdays)

Cron Syntax Explained

The five fields in a standard cron expression represent:

Field Structure

Field Values Special Characters
Minute 0-59 * , - /
Hour 0-23 * , - /
Day of Month 1-31 * , - / L W
Month 1-12 * , - /
Day of Week 0-6 * , - / L #
Pro Tip: Use the Cron Parser API to validate expressions and get human-readable descriptions, making it easier to understand complex schedules.

Using the Cron Parser API

TinyFn provides a simple endpoint to parse cron expressions:

API Request
GET https://api.tinyfn.io/v1/parse/cron?expression=0 9 * * 1-5
Headers: X-API-Key: your-api-key
Response
{
  "expression": "0 9 * * 1-5",
  "valid": true,
  "description": "At 9:00 AM, Monday through Friday",
  "fields": {
    "minute": "0",
    "hour": "9",
    "dayOfMonth": "*",
    "month": "*",
    "dayOfWeek": "1-5"
  }
}

Parameters

Parameter Type Description
expression string The cron expression to parse (required)
timezone string Timezone for the schedule (default: UTC)

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/parse/cron?expression=0 9 * * 1-5',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.description); // "At 9:00 AM, Monday through Friday"

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/parse/cron',
    params={'expression': '0 9 * * 1-5'},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['description'])  # "At 9:00 AM, Monday through Friday"

cURL

curl "https://api.tinyfn.io/v1/parse/cron?expression=0%209%20*%20*%201-5" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Schedule Validation: Validate user-entered cron expressions before saving
  • UI Display: Show human-readable schedule descriptions to users
  • Debug Scheduling: Understand complex cron expressions in legacy code
  • Job Scheduling: Build scheduling interfaces for background jobs
  • Documentation: Auto-generate schedule documentation from cron expressions

Best Practices

  1. Always validate: Parse and validate cron expressions before saving to database
  2. Show descriptions: Display human-readable descriptions to help users understand schedules
  3. Handle timezones: Always specify timezone when dealing with schedules
  4. Test edge cases: Test expressions for month-end and year-end scenarios

Try the Cron Parser API

Get your free API key and start parsing cron expressions in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key