- Note, this code and file structure was generated using ChatGPT. I know there are easy improvements that can be made, but the script works as is.
- Everybody needs mock data when developing for apple health products. Unfortunately, it's hard to come by this data. My solution? Import my own apple health data, then convert it into a usable format.
- This is a package to take that apple healthkit XML and turn it into usable JSON. The script also allows for you to convert the data into useable javascript objects.
- It takes about 2 minutes to set up. The script itself can vary in time, depending on the amount of data you are using.
- Export your apple health data.
- Open the Health app
- On the top right, click your profile icon
- Scroll all the way down, click the
Export All Health Databutton - Hit Export and the app will create a .Zip file containing XML data you will need.
- Get this ZIP to your laptop. Airdrop, email, dropbox, whatever.
- Install the scripts
git clone https://github.com/sudomichael/AppleHealthDataToJSON.gitcd AppleHealthDataToJSON
- Open your apple health data ZIP, add the .XML data to the root directory of AppleHealthDataToJSON.
- Rename the XML file is to
export.xmlif it isn't already
python3 main.py- Copy the
datadirectory in to your javascript project. - Use as needed, i.e
import HealthData from src/data/index const heartRateData = HealthData.HeartRate; heartRateData.forEach(heartRate => console.log(heartRate.value));
- Pass the
--jsonargument to the script when runningpython3 main.py --json
- Update
main.pyas you see fit, to only run certain scripts or not.