Skip to main content

Use standard formats

Add format to a string when your application expects a standard representation. Struct enforces supported formats during generation, including calendar rules for dates and timezone requirements for times.

Choose a format​

ValueformatExample
Datedate2026-11-14
Timetime09:30:00Z
Timestampdate-time2026-11-14T09:30:00Z
DurationdurationPT45M

UUIDs, IPv4 addresses and JSON pointers also have supported formats. See the format reference for the full list. Use a pattern for a custom shape instead.

Example: normalize a scheduled time​

The request below converts a human-readable date and time to an RFC 3339 timestamp.

Save event-time.schema.json beside your client:

event-time.schema.json
{
"type": "object",
"properties": {
"starts_at": {
"type": "string",
"format": "date-time",
"description": "Convert the stated start date and time to an RFC 3339 timestamp, preserving the timezone specified in the input."
}
},
"required": ["starts_at"],
"additionalProperties": false
}
Before you run this example

Call https://api.blatent.ai from your server. Set your API key in the same terminal where you run the example:

export BLATENT_API_KEY='YOUR_SERVICE_KEY'

Python requires Python 3.10+ and HTTPX:

python -m pip install "httpx>=0.28,<1"

TypeScript requires Node.js 24+ and uses its built-in fetch. The cURL examples require curl and jq.

Save the displayed files and the selected client in one directory. Run the client there with python example.py, node example.ts or bash example.sh. Downloads use the example's name in place of example.

import json
import os
from pathlib import Path
import httpx

request = {
"input": "Maintenance starts at 09:30 UTC on 14 November 2026.",
"schema": json.loads(Path("event-time.schema.json").read_text(encoding="utf-8")),
}
with httpx.Client(
base_url="https://api.blatent.ai",
headers={"Authorization": f"Bearer {os.environ['BLATENT_API_KEY']}"},
timeout=195,
) as client:
response = client.post("/v1/resolve", json=request)
response.raise_for_status()
print(json.dumps(response.json()["output"]))

Illustrative output:

{"starts_at":"2026-11-14T09:30:00Z"}

What a format checks​

A date must be a real calendar date, including leap-year rules. A time or timestamp must include a timezone. The Z in this example means UTC.

A valid representation can still describe the wrong event or instant. Supply enough context to resolve ambiguous dates and timezones, and describe which value to normalize.

Formats check individual values. For a rule such as an end time following its start, see date relationships.