Medications export JSON format
The JSON file Health Exporter & Shortcuts writes when it exports medication doses on iOS 26 and later: one entry per logged dose, which statuses are kept, how each dose is named, and the rules that keep it stable between versions.
Purpose #
Defines the JSON a medications export produces: its top-level shape, the metadata header, the fields on a dose entry and where each comes from in HealthKit, which doses are left out, what the file can and cannot say about access, the naming of the file, and the rules that keep the format usable by the automations built on top of it across versions.
Requirements #
Requirement: Medications export needs iOS 26 #
Medications are exported only on iOS 26 or later, whose HealthKit opened them to other apps. Written since 1.8.0.
On iOS 17 to 25 the Medications tab is shown with a note saying it needs iOS 26, and nothing in it can be pressed. The Export Medications action in Shortcuts fails with the message “Exporting medications needs iOS 26 or later.” and produces no file.
Scenario: Shortcut run on iOS 25 #
- WHEN an automation runs Export Medications on iOS 25
- THEN the run fails with that message, and no file is produced
Requirement: JSON only #
A medications export SHALL be a single JSON file. There is no Markdown rendering of medications: the
File Format option that offers Markdown for health data and workouts is not offered in the Medications
tab, and the Export Medications action has no format parameter. The Markdown format described in
markdown-export-format.md does not cover this export.
Requirement: Medications JSON top-level structure #
The exported file SHALL be a dictionary with exactly two keys: exportInfo containing metadata, and
doseEvents containing an array of dose entries.
Scenario: Export with doses #
- WHEN the user exports the doses logged from 2026-08-01 to 2026-08-03
- THEN the JSON SHALL have the structure:
{
"doseEvents": [ ... ],
"exportInfo": { ... }
}
Scenario: No doses in the date range #
- WHEN no dose matches the requested range, or no medication is shared with the app
- THEN the JSON SHALL still include the
doseEventskey with an empty array
Requirement: Medications 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 (YYYY-MM-DD)endDate: the end date of the requested range (YYYY-MM-DD)doseEventCount: the number of entries indoseEventsappVersion: 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 apartpendingAuthorizations(optional): see “The medications picker was never shown”
Scenario: Metadata reflects export parameters #
- WHEN the user exports from 2026-08-01 to 2026-08-03 and 6 doses are found
- THEN the exportInfo SHALL contain:
{
"appVersion": "1.0.0",
"buildNumber": "42",
"doseEventCount": 6,
"endDate": "2026-08-03",
"exportDate": "2026-08-04T09:41:00Z",
"startDate": "2026-08-01"
}
Requirement: Which medications are exported #
An export SHALL contain the doses of the medications the person chose to share with the app, and only those. HealthKit authorizes medications one by one, in a system list in which the person picks them; sharing a medication shares the doses logged for it, with no separate authorization for doses.
The app shows that list the first time the person exports from its Medications tab, and again whenever they tap Choose Medications there, which is also how they change their choice. When a medication is added to Health later, the Health app offers the person a switch to share it with the app as well.
The file SHALL NOT be read as a statement about access, because HealthKit does not tell the app any of the following, and the export therefore cannot say:
- whether the person declined to share some or all of their medications
- which medications they chose
- whether a medication added to Health later was shared
An empty doseEvents is the same file whether nothing was logged in the range, nothing was shared,
or the list was never shown.
Requirement: The medications picker was never shown #
The Export Medications action in Shortcuts never shows the medications list, because an automation has
no screen to show it on. It exports what the person has already shared, which is nothing until they
have chosen in the app. While the app has no record of the person ever completing the list, a Shortcuts
export SHALL carry pendingAuthorizations in exportInfo, holding exactly the identifier of the
medication type:
"pendingAuthorizations": [
"HKDataTypeUserAnnotatedMedicationConcept"
]
It never lists the identifier of the dose type, which has no authorization of its own. The key SHALL be absent once the person has completed the list in the app, whatever they chose in it, and SHALL never be an empty array. Exports from the app itself never carry it, since the app shows the list before its first medication export. The first such run also posts one notification, which opens the Medications tab and the list.
The record is the app’s own and is kept on the device, since HealthKit cannot tell the app whether the list was ever shown. Deleting the app clears it.
Scenario: Shortcut set up before the app was opened #
- WHEN an automation exports medications and the person has never been through the list in the app
- THEN
doseEventsSHALL be an empty array,doseEventCountSHALL be 0, andexportInfoSHALL contain thependingAuthorizationsabove
Scenario: After choosing in the app #
- WHEN the person has completed the list in the app, sharing some medications or none
- THEN
exportInfoSHALL NOT contain apendingAuthorizationskey
Requirement: Dose entry format #
Each entry in the doseEvents array SHALL be a dictionary describing one HKMedicationDoseEvent,
exactly as logged: one entry per dose, never aggregated. Optional keys SHALL be omitted when they have
no value, never written as null.
| Key | Always present | HealthKit source | Meaning |
|---|---|---|---|
medication | no | HKUserAnnotatedMedication.nickname, or medication.displayText when the nickname is absent or blank | The medication’s name, resolved through the dose’s medicationConceptIdentifier. See “Naming the medication” |
startDate | yes | HKSample.startDate | ISO 8601 timestamp of the time the person picked when logging the dose. It is the moment of logging unless they changed it, which they can, for instance to log a dose taken earlier |
endDate | yes | HKSample.endDate | ISO 8601 timestamp HealthKit holds as the dose’s end |
status | yes | logStatus | What was logged. See “Dose statuses” |
scheduleType | yes | scheduleType | schedule for a dose logged against a reminder, asNeeded for one logged on its own |
scheduledDate | no | scheduledDate | ISO 8601 timestamp the scheduled dose was due at. HealthKit holds it for every schedule dose and never for an asNeeded one |
quantity | no | doseQuantity | The amount logged as taken, in unit. Absent when HealthKit holds none |
scheduledQuantity | no | scheduledDoseQuantity | The amount the schedule asked for, in unit. HealthKit holds it for every schedule dose and never for an asNeeded one |
unit | yes | unit | The unit the dose was logged with, as HealthKit writes it, such as count or mL |
source | yes | sourceRevision.source.name | Name of the app or device that logged the dose, the same convention as a workout’s source |
uuid | yes | HKSample.uuid | The dose’s HealthKit UUID, which lets a consumer deduplicate across exports |
Numbers are JSON numbers, written as HealthKit holds them, without rounding. A skipped dose carries the quantity HealthKit holds for it, which Apple describes as 0, since nothing was taken.
The medication’s clinical codes (relatedCodings, such as RxNorm), its form and its schedule are not
exported.
Scenario: Scheduled dose taken #
- WHEN the person logged a scheduled vitamin as taken, 12 minutes after its 08:00 reminder
- THEN its entry SHALL be:
{
"endDate": "2026-08-01T08:12:03Z",
"medication": "Vitamin D",
"quantity": 1,
"scheduledDate": "2026-08-01T08:00:00Z",
"scheduledQuantity": 1,
"scheduleType": "schedule",
"source": "Health",
"startDate": "2026-08-01T08:12:03Z",
"status": "taken",
"unit": "count",
"uuid": "A1B2C3D4-E5F6-4A7B-8C9D-0E1F2A3B4C5D"
}
Scenario: As needed dose #
- WHEN the person logged two tablets of a painkiller with no reminder
- THEN its entry SHALL contain
"scheduleType": "asNeeded"and"quantity": 2, and SHALL NOT containscheduledDateorscheduledQuantity
Scenario: Dose with no quantity #
- WHEN HealthKit holds no quantity for a dose
- THEN its entry SHALL NOT contain a
quantitykey
Requirement: Naming the medication #
A dose carries no name of its own in HealthKit, only the concept identifier of its medication. The
export SHALL resolve it against the medications shared with the app, archived ones included, so a
dose logged before its medication was archived keeps its name. The name is the medication’s nickname,
or its own name (displayText) when the nickname is absent or blank.
When one medication is listed twice, archived and added again, the active one SHALL name its doses, and between two equals the first name in alphabetical order, so that two exports of the same data agree.
A dose whose medication cannot be resolved SHALL still be exported, with every other field, and
without the medication key. medication is therefore optional, and a consumer SHALL NOT assume it.
Scenario: Dose of an archived medication #
- WHEN a dose was logged for a medication that has since been archived in Health
- THEN its entry SHALL carry that medication’s name
Scenario: Medication that cannot be resolved #
- WHEN no shared medication matches a dose’s concept identifier
- THEN its entry SHALL NOT contain a
medicationkey, and SHALL contain every other key that applies
Requirement: Dose statuses #
status SHALL be one of:
taken: the person logged that they took the doseskipped: the person logged that they skipped itsnoozed: the person snoozed the reminder for itnotLogged: the person cleared a status they had logged before, which HealthKit keeps as a dose of its own
HealthKit’s two other statuses, notInteracted (a reminder nobody answered) and notificationNotSent
(a reminder the system failed to deliver), SHALL never be exported. They are reminder slots nobody
touched: nothing was logged, and on a scheduled medication they can outnumber the real entries many
times over. They are kept out by the query itself, so they never reach the app.
The cost is real, and stated here so nobody has to rediscover it: an adherence analysis cannot tell a missed dose from a day with no reminder scheduled. If that turns out to matter, the way back is a new optional key or an export option, never a change of meaning for the values above.
A status a later iOS adds SHALL NOT be exported until a release maps it to a name of its own, which is an addition this format allows.
Scenario: A reminder nobody answered #
- WHEN a scheduled reminder went unanswered
- THEN no entry SHALL be exported for it
Requirement: Schedule types #
scheduleType SHALL be schedule or asNeeded. A schedule type the app does not recognise, such as
one introduced by a later iOS, SHALL be exported as unknown_<rawValue> rather than costing the export
the dose, the rule activity types follow.
Requirement: Which doses belong to the range #
A dose SHALL be selected by startDate, the time the person picked when logging it, and not by
when the logging happened or by scheduledDate. The range covers every day it touches, from the start
of its first day to the end of its last, so a range that starts or ends mid day still reports those
days in full, as for the other exports.
Scenario: A dose logged for an earlier time #
- WHEN the person logs today a dose they took yesterday evening, and sets its time to yesterday evening
- THEN the dose SHALL belong to yesterday, and an export of today alone SHALL NOT contain it
Scenario: A reminder answered the next day #
- WHEN the person answers today a reminder that was due yesterday
- THEN the dose SHALL belong to the day of the time picked when logging it, whichever day that is, and its
scheduledDateSHALL still say yesterday
Requirement: Dose ordering #
Dose entries SHALL be ordered by startDate ascending, and by uuid between two doses logged at the
same instant, so that two exports of the same data list them alike.
Requirement: The device is locked #
Health data cannot be read while the device is locked. An export that meets the lock SHALL fail without producing a file, rather than produce one with no doses that would look like a successful run.
Requirement: Medications JSON encoding settings #
The JSON output SHALL use sorted keys and pretty printing, matching the other two exports.
Requirement: Medications file naming #
The exported file SHALL be named medications_export_<timestamp>_<suffix>.json where <timestamp> is
a Unix timestamp in seconds and <suffix> is an 8-character unique suffix. The file SHALL use UTF-8
encoding and application/json MIME type.
Scenario: File is created with correct name #
- WHEN a medications export is performed at Unix timestamp 1785836460
- THEN the file SHALL be named
medications_export_1785836460_<suffix>.json
Requirement: Medications format stability across versions #
The medications JSON SHALL be covered by the “Format stability across versions” requirement of
export-format.md, which holds the normative rules for every export, from its
first release. Its golden fixture SHALL be HealthExporterTests/Fixtures/medications_export_golden.json,
with medications_export_pending_golden.json beside it pinning pendingAuthorizations.
Scenario: Key renamed by accident #
- WHEN a change renames
scheduledQuantityor dropsuuidfrom a dose 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
A complete example #
This is the file the app’s format test compares the encoder’s output against, byte for byte. Its values are invented, and it packs into one file every shape a dose entry can take: a scheduled dose taken and the same one skipped, as needed doses with no scheduled date or quantity, a snoozed reminder with no quantity logged, and a cleared status whose medication cannot be resolved, which therefore has no medication key. The last dose is named after a medication that has since been archived.
{
"doseEvents" : [
{
"endDate" : "2026-08-01T08:12:03Z",
"medication" : "Vitamin D",
"quantity" : 1,
"scheduledDate" : "2026-08-01T08:00:00Z",
"scheduledQuantity" : 1,
"scheduleType" : "schedule",
"source" : "Health",
"startDate" : "2026-08-01T08:12:03Z",
"status" : "taken",
"unit" : "count",
"uuid" : "A1B2C3D4-E5F6-4A7B-8C9D-0E1F2A3B4C5D"
},
{
"endDate" : "2026-08-01T22:40:11Z",
"medication" : "Ibuprofen 200 mg Oral Tablet",
"quantity" : 2,
"scheduleType" : "asNeeded",
"source" : "Health",
"startDate" : "2026-08-01T22:40:11Z",
"status" : "taken",
"unit" : "count",
"uuid" : "C3D4E5F6-A7B8-4C9D-8E0F-2A3B4C5D6E7F"
},
{
"endDate" : "2026-08-02T08:31:40Z",
"medication" : "Vitamin D",
"quantity" : 0,
"scheduledDate" : "2026-08-02T08:00:00Z",
"scheduledQuantity" : 1,
"scheduleType" : "schedule",
"source" : "Apple Watch",
"startDate" : "2026-08-02T08:31:40Z",
"status" : "skipped",
"unit" : "count",
"uuid" : "B2C3D4E5-F6A7-4B8C-9D0E-1F2A3B4C5D6E"
},
{
"endDate" : "2026-08-03T08:00:05Z",
"medication" : "Vitamin D",
"scheduledDate" : "2026-08-03T08:00:00Z",
"scheduledQuantity" : 1,
"scheduleType" : "schedule",
"source" : "Health",
"startDate" : "2026-08-03T08:00:05Z",
"status" : "snoozed",
"unit" : "count",
"uuid" : "D4E5F6A7-B8C9-4D0E-9F1A-3B4C5D6E7F80"
},
{
"endDate" : "2026-08-03T21:05:00Z",
"quantity" : 1,
"scheduledDate" : "2026-08-03T21:00:00Z",
"scheduledQuantity" : 1,
"scheduleType" : "schedule",
"source" : "Health",
"startDate" : "2026-08-03T21:05:00Z",
"status" : "notLogged",
"unit" : "count",
"uuid" : "E5F6A7B8-C9D0-4E1F-8A2B-4C5D6E7F8091"
},
{
"endDate" : "2026-08-03T23:10:30Z",
"medication" : "Cough syrup",
"quantity" : 7.5,
"scheduleType" : "asNeeded",
"source" : "Health",
"startDate" : "2026-08-03T23:10:30Z",
"status" : "taken",
"unit" : "mL",
"uuid" : "F6A7B8C9-D0E1-4F2A-9B3C-5D6E7F8091A2"
}
],
"exportInfo" : {
"appVersion" : "1.0.0",
"buildNumber" : "42",
"doseEventCount" : 6,
"endDate" : "2026-08-03",
"exportDate" : "2026-08-04T09:41:00Z",
"startDate" : "2026-08-01"
}
}