HealthKit to JSONL vs JSON: one snapshot survives a cut sync, the other gives you nothing

2026-10-09来源 dev.to DataEnglish

Two apps can write the exact same Apple Health records to disk and behave nothing alike the moment a sync gets interrupted.

I benchmarked it on 2026-10-08: 3,200 daily records, 400 days across 8 metrics, written once as a JSON array and once as JSONL, then both truncated at 100,000 bytes to simulate a cut-off iCloud sync. The JSON array returned a parse error and 0 recoverable records. The JSONL file gave back 1,355. The two files differed by 1 byte.

The reason is structural. A JSON array is one document, valid only once the closing bracket lands, so a half-written snapshot is not JSON at all. JSONL is one object per line, valid incrementally, so a reader keeps every complete record it already has.

Check any snapshot yourself:

jq -c . yourfile.jsonl jq -c 'select(.metric=="hrv_sdnn")' health.jsonl grep 2026-10-07 health.jsonl 

For the other side of the trade, HealthMirror writes plain-text JSONL into its own iCloud container and its local server reads per-metric subfolders. MetricBridge takes the whole-file route: a compact .health-cache.json snapshot a zero-dependency MCP server reads, with get_freshness reporting the age. Different read patterns, different formats.

Full write-up with the benchmark table and the failure modes: https://www.healthexport.dev/blog/healthkit-to-jsonl-vs-json?utm_source=devto&utm_medium=social&utm_campaign=exp-20261008-hea195-jsonl

原文:https://www.a8q9.cn/en/article/healthkit-to-jsonl-vs-json-one-snapshot-survives-a-cut-sync-the-other-gives-you--3b4792.html

相关文章