DEV Community

Philip D'Souza
Philip D'Souza

Posted on

Apple Health export.xml to JSON: stop using DOM parsers

Most "convert Apple Health XML to JSON" guides hand you a Python script with xml.etree.ElementTree. ElementTree is a DOM parser. It loads the entire XML tree into RAM before you can read a single node.

A long-term Apple Watch user has a 1.8GB export.xml. That is roughly 4.26 million records. Run a DOM parser against it and the process swaps to disk and dies before it returns one record.

What actually works:

  • Streaming SAX parsers. xml.sax or lxml.etree.iterparse hold one record at a time. Constant memory, multi-GB files, no crash.
  • Dedicated CLI tools. healthsync (Go, SQLite output) parses a 950MB export in 30 seconds at ~10MB heap. openhealth (Bun, saxes SAX) handles a 1M-record file in 5 seconds at 5MB heap. vpetersson/apple-health-mcp-server (Rust + DuckDB) takes a 2.5GB export in under a minute.
  • Skip the XML entirely. The Health Export AI iOS app reads HealthKit directly with read-only permission and writes JSON to iCloud. No export.xml, no computer, no manual transfer of a 1.8GB file.

If you only need a one-time conversion of an existing export.xml, use a browser converter or a Python script with a streaming parser. If you plan to query your health data with AI agents regularly, skip the XML loop.

Full guide with all four methods, benchmarks, and code samples: Apple Health export.xml to JSON: The Complete Guide (2026)

Top comments (0)