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.

Health Exporter & Shortcuts is a paid iPhone app: US$2.99 once on the App Store, which shows the price in your currency. No subscription and no in-app purchases.

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 #

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 #

{
  "doseEvents": [ ... ],
  "exportInfo": { ... }
}

Scenario: No doses in the date range #

Requirement: Medications export metadata header #

The exportInfo object SHALL contain:

Scenario: Metadata reflects export parameters #

{
  "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:

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 #

Scenario: After choosing in the app #

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.

KeyAlways presentHealthKit sourceMeaning
medicationnoHKUserAnnotatedMedication.nickname, or medication.displayText when the nickname is absent or blankThe medication’s name, resolved through the dose’s medicationConceptIdentifier. See “Naming the medication”
startDateyesHKSample.startDateISO 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
endDateyesHKSample.endDateISO 8601 timestamp HealthKit holds as the dose’s end
statusyeslogStatusWhat was logged. See “Dose statuses”
scheduleTypeyesscheduleTypeschedule for a dose logged against a reminder, asNeeded for one logged on its own
scheduledDatenoscheduledDateISO 8601 timestamp the scheduled dose was due at. HealthKit holds it for every schedule dose and never for an asNeeded one
quantitynodoseQuantityThe amount logged as taken, in unit. Absent when HealthKit holds none
scheduledQuantitynoscheduledDoseQuantityThe amount the schedule asked for, in unit. HealthKit holds it for every schedule dose and never for an asNeeded one
unityesunitThe unit the dose was logged with, as HealthKit writes it, such as count or mL
sourceyessourceRevision.source.nameName of the app or device that logged the dose, the same convention as a workout’s source
uuidyesHKSample.uuidThe 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 #

{
  "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 #

Scenario: Dose with no quantity #

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 #

Scenario: Medication that cannot be resolved #

Requirement: Dose statuses #

status SHALL be one of:

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 #

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 #

Scenario: A reminder answered the next day #

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 #

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 #

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"
  }
}

All format documents · Guides