SDK & Validation
Serialization & History
Parse and serialize FitData JSON and JSONL streams, and compute active record views with tombstones.
fitdata provides bounded text parsers, lossless serializers, and deterministic revision resolution.
JSON documents
import { parseDocument, serializeDocument } from "fitdata";
const parsed = parseDocument(jsonText);
if (parsed.ok) {
const output = serializeDocument(parsed.value);
}parseDocument enforces the 16 MiB UTF-8 size limit, parses JSON, and runs full validateDocument structural and semantic checks.
JSON Lines (JSONL)
FitData JSONL places the document header on line 1 (all document envelope fields except records), followed by one JSON-serialized record per subsequent line:
import { parseJsonLines, serializeJsonLines } from "fitdata";
const jsonl = serializeJsonLines(document);
const roundTripped = parseJsonLines(jsonl);- Preserves exact decimal strings,
nullseries samples, extensions, and all included historical revisions. - Rejects malformed lines, trailing invalid headers, or inputs exceeding
16 MiBor10,000records.
Active view and tombstones (currentRecords)
Because FitData documents can include multiple revisions of the same logical id alongside core.tombstone deletions, call currentRecords(document) to obtain the current active set:
import { currentRecords, parseDocument } from "fitdata";
const parsed = parseDocument(historyJson);
if (parsed.ok) {
const active = currentRecords(parsed.value);
// Contains only the highest non-tombstone revision for each logical ID
}Rules:
- Order of records in
document.recordsnever changes the output. - If the highest revision for an
idis acore.tombstone, that entity is omitted. - Replaying a lower live revision does not undelete a tombstoned record; only a strictly higher live revision restores it.
- Versioned entities (
training.routine,nutrition.food,lab.biomarker,lab.test) are keyed by{ id, version }and retained alongside revisioned entities.