Health export JSON format
The JSON file Health Exporter & Shortcuts writes when it exports Apple Health data: its keys, units, dates and sleep stages, and the rules that keep it stable between versions.
Purpose #
Defines the structure of the exported JSON file: the top-level shape, the export metadata header, daily entries, the sleep stage breakdown, date ordering, encoder settings, and the exported file’s name.
Requirements #
Requirement: JSON top-level structure #
The exported JSON file SHALL be a dictionary with an exportInfo key containing metadata, plus one key per exported data type containing an array of daily entries.
Scenario: Export with two data types #
- WHEN the user exports stepCount and restingHeartRate for Feb 7-9, 2026
- THEN the JSON SHALL have the structure:
{
"exportInfo": { ... },
"stepCount": [ ... ],
"restingHeartRate": [ ... ]
}
Scenario: Data type with no data #
- WHEN a selected data type has no data in the date range
- THEN the JSON SHALL include that type’s key with an empty array
Scenario: Data type the iOS version does not have #
- WHEN a selected data type exists only on a later iOS than the one the export runs on, such as
heartRateVariabilityRMSSDbefore iOS 27 - THEN the JSON SHALL NOT include that type’s key, and
exportInfo.dataTypesSHALL NOT list it
Requirement: Export metadata header #
The exportInfo object SHALL contain:
exportDate: ISO 8601 timestamp of when the export was performedstartDate: the start date of the requested range (ISO 8601 date)endDate: the end date of the requested range (ISO 8601 date)dataTypes: array of JSON key names for the types included in the exportappVersion: the app’s marketing version string, which is the same for every build of a releasebuildNumber: the build the export was produced by, which tells two binaries of one version apart. Written since 1.7.0; an export from an earlier version has no such keymeasurementSystem:"metric"or"us", the system theunitfields were converted topendingAuthorizations(optional): see the requirement below
Scenario: Metadata reflects export parameters #
- WHEN the user exports stepCount and weight from 2026-02-01 to 2026-02-07 on a metric device
- THEN the exportInfo SHALL contain:
{
"exportDate": "2026-02-07T15:30:00Z",
"startDate": "2026-02-01",
"endDate": "2026-02-07",
"dataTypes": ["stepCount", "weight"],
"appVersion": "1.0.0",
"buildNumber": "42",
"measurementSystem": "metric"
}
Scenario: Measurement system follows the device locale #
- WHEN the device locale uses US customary units
- THEN
measurementSystemSHALL be"us"and theunitfields SHALL carry the US units (for examplelbfor weight)
Requirement: Types never authorized are listed #
The Export Health Data action in Shortcuts never asks for HealthKit authorization, because an automation has no screen to show the request on. It exports what the user has already allowed. When a type it exports has never been offered to the user, typically because an update started reading it, exportInfo SHALL carry pendingAuthorizations: an array of the full HealthKit identifiers of those types (for example HKQuantityTypeIdentifierHeartRateVariabilitySDNN), sorted ascending.
The key SHALL be absent when no type is pending, and SHALL never be an empty array. Exports from the app itself never carry it, since the app asks before it exports. Written since 1.8.0; an export from an earlier version has no such key.
A pending type keeps its key in the file, with an empty array, like any type with no data. A type the user denied is not pending and is not listed: HealthKit does not tell an app which reads were denied.
Scenario: A new type read from an automation #
- WHEN an automation exports every type after an update that reads heart rate variability, and the user has not opened the app since
- THEN
heartRateVariabilitySHALL be an empty array, andexportInfoSHALL contain:
"pendingAuthorizations": ["HKQuantityTypeIdentifierHeartRateVariabilitySDNN"]
Scenario: Nothing pending #
- WHEN every exported type has been offered to the user, whatever they answered
- THEN
exportInfoSHALL NOT contain apendingAuthorizationskey
Requirement: Daily entry format #
Each entry in a data type’s array SHALL be a dictionary with at least these three keys:
value: numeric value (Double)date: ISO 8601 date string (YYYY-MM-DD, no time component)unit: string representing the unit of measurement
Entries for non-sleep data types SHALL carry these three keys and nothing else. sleepTime adds
stages, per the requirement below.
Scenario: Step count entry #
- WHEN the user had 8432 steps on 2026-02-10
- THEN the entry SHALL be:
{ "value": 8432, "date": "2026-02-10", "unit": "count" }
Scenario: Resting heart rate entry #
- WHEN the user’s average resting heart rate on 2026-02-10 was 63 bpm
- THEN the entry SHALL be:
{ "value": 63, "date": "2026-02-10", "unit": "bpm" }
Requirement: Heart rate variability, SDNN and RMSSD #
HealthKit records heart rate variability as two separate measures, and the export keeps them under two separate keys. Both SHALL use the daily entry format above, with unit "ms" (milliseconds) on every measurement system, and value the average of the samples HealthKit holds for that day. A day with no sample SHALL have no entry, never a zero.
heartRateVariabilityis SDNN, HealthKit’sHKQuantityTypeIdentifierHeartRateVariabilitySDNN. It is the type every version of the app has exported under this key, and the key SHALL keep meaning SDNN.heartRateVariabilityRMSSDis RMSSD, HealthKit’sHKQuantityTypeIdentifierHeartRateVariabilityRMSSD, which exists only on iOS 27 and later. An export from a version of the app that could not read it, or from an iPhone running an iOS earlier than 27, has no such key.
On an iOS earlier than 27 the app does not list RMSSD and an export of every type does not include it. The Export Health Data action in Shortcuts still offers it, because Shortcuts cannot hide an option on one iOS version; an action that selects it there exports the other types it selects, and leaves RMSSD out of the file and out of pendingAuthorizations. An action that selects only RMSSD there has nothing to export: it SHALL fail without writing a file, with a message that names the type and the iOS version it needs.
Scenario: Both measures on the same day #
- WHEN the user exports both types for 2026-11-12 on iOS 27, with an SDNN average of 38.25 ms and an RMSSD average of 31.5 ms
- THEN the JSON SHALL contain:
"heartRateVariability": [ { "value": 38.25, "date": "2026-11-12", "unit": "ms" } ],
"heartRateVariabilityRMSSD": [ { "value": 31.5, "date": "2026-11-12", "unit": "ms" } ]
Scenario: A shortcut that selects RMSSD on an earlier iOS #
- WHEN an Export Health Data action selecting stepCount and heartRateVariabilityRMSSD runs on iOS 26
- THEN the JSON SHALL contain
stepCountand noheartRateVariabilityRMSSDkey, andexportInfo.dataTypesSHALL be["stepCount"]
Scenario: A shortcut that selects only RMSSD on an earlier iOS #
- WHEN an Export Health Data action selecting only heartRateVariabilityRMSSD runs on iOS 26
- THEN the action SHALL fail with no file, and its message SHALL say that Heart Rate Variability (RMSSD) needs iOS 27 or later
Requirement: Sleep entries include stage breakdown #
Each entry in the sleepTime array SHALL include an additional stages object with per-stage durations in minutes:
core: light/intermediate sleep (asleepCore)deep: deep/slow-wave sleep (asleepDeep)rem: REM sleep (asleepREM)awake: awake periods within the sleep sessionunspecified: sleep recorded without stage classification
The value field SHALL remain the sum of core + deep + rem only, preserving backward compatibility.
Scenario: Sleep entry with stage breakdown #
- WHEN the user had 417.625 minutes of sleep on 2026-02-08
- THEN the entry SHALL be:
{
"value": 417.625,
"date": "2026-02-08",
"unit": "min",
"stages": {
"core": 244.5,
"deep": 77.25,
"rem": 95.875,
"awake": 14.5,
"unspecified": 0
}
}
Scenario: Non-sleep entries do not include stages #
- WHEN exporting a non-sleep data type like stepCount
- THEN the entry SHALL NOT include a
stageskey
Requirement: Date ordering #
Entries within each data type’s array SHALL be ordered chronologically (oldest date first).
Scenario: Multi-day export ordering #
- WHEN exporting data for Feb 7-9
- THEN the entries SHALL appear in order: Feb 7, Feb 8, Feb 9
Requirement: JSON encoding settings #
The JSON output SHALL use sorted keys for consistent output and SHALL use pretty-printing (indented) for human readability.
Scenario: JSON is human-readable #
- WHEN the JSON file is exported
- THEN the content SHALL be indented and keys SHALL appear in alphabetical order within each object
Requirement: File naming #
The exported file SHALL be named health_export_<timestamp>_<suffix>.json where <timestamp> is a Unix timestamp in seconds and <suffix> is an 8-character unique suffix that keeps concurrent exports from overwriting each other. The file SHALL use UTF-8 encoding and application/json MIME type.
Scenario: File is created with correct name #
- WHEN an export is performed at Unix timestamp 1770742497
- THEN the file SHALL be named
health_export_1770742497_<suffix>.json
Scenario: Two exports in the same second #
- WHEN two exports complete within the same Unix second
- THEN the two files SHALL have different names and neither SHALL overwrite the other
Requirement: Format stability across versions #
The exported JSON SHALL be treated as a public contract, because users build Apple Shortcuts automations on top of its keys and receive no migration path. Between released versions the app SHALL only add top-level keys, data type keys, or optional entry fields. Renaming a key, removing a key, changing a value’s type or unit, or changing a date format SHALL require an explicit decision, an update to this spec, and a note in the release notes.
The repository SHALL keep committed golden fixtures of the encoded output and SHALL compare the encoder’s output against them byte for byte, so that any change to the format appears as a reviewable diff rather than as a silent behaviour change.
Scenario: A key is renamed by accident #
- WHEN a change renames an existing JSON key or drops a field from an entry
- THEN the golden fixture comparison SHALL fail, and the failure SHALL only be resolved by re-recording the fixture and reviewing the resulting diff
Scenario: A new optional field is added #
- WHEN a change adds a new optional field to an entry without touching existing fields
- THEN the golden fixture SHALL be re-recorded, the diff SHALL show only additions, and existing consumers SHALL keep working unchanged
A complete example #
This is the file the app’s format test compares the encoder’s output against, byte for byte, so it is exactly what an export looks like. Its values are invented. Two details are deliberate: numbers are written unrounded, so 63.1 appears as 63.100000000000001, which any JSON parser reads back as 63.1; and vo2Max, selected but with no data in the range, is an empty array.
{
"exportInfo" : {
"appVersion" : "1.0.0",
"buildNumber" : "42",
"dataTypes" : [
"stepCount",
"weight",
"sleepTime",
"restingHeartRate",
"vo2Max"
],
"endDate" : "2026-02-10",
"exportDate" : "2026-02-10T18:30:00Z",
"measurementSystem" : "metric",
"startDate" : "2026-02-07"
},
"restingHeartRate" : [
{
"date" : "2026-02-09",
"unit" : "bpm",
"value" : 63.100000000000001
}
],
"sleepTime" : [
{
"date" : "2026-02-08",
"stages" : {
"awake" : 14.5,
"core" : 244.5,
"deep" : 77.25,
"rem" : 95.875,
"unspecified" : 0
},
"unit" : "min",
"value" : 417.625
}
],
"stepCount" : [
{
"date" : "2026-02-07",
"unit" : "count",
"value" : 8432
},
{
"date" : "2026-02-08",
"unit" : "count",
"value" : 10250
},
{
"date" : "2026-02-09",
"unit" : "count",
"value" : 6117
}
],
"vo2Max" : [
],
"weight" : [
{
"date" : "2026-02-09",
"unit" : "kg",
"value" : 72.25
}
]
}