R: Read Garmin activity export summary to a dataframe

The Garmin export is a deeply nested JSON structure. It only appears to fill in columns where there is data. Like so:

  {
    "summarizedActivitiesExport": [
      {
        "activityId": 9342780544,
        "uuidMsb": -8608655323230679000,
        "uuidLsb": -8443901297724183000,
        "name": "Ambler Running",
        "activityType": "running",
        "userProfileId": 106383175,
        "timeZoneId": 149,
        "beginTimestamp": 1659703707000,
        "eventTypeId": 9,
        ...

The following code will read it to a dataframe:

df <- data.table::rbindlist(read_json(filename)[[1]]$summarizedActivitiesExport, fill=TRUE) 

df
activityId uuidMsb uuidLsb name activityType userProfileId timeZoneId beginTimestamp eventTypeId rule
1: 9342780544 -8.608655e+18 -8.443901e+18 Ambler Running running 106383175 149 1.659704e+12 9 private
2: 9311888059 -3.045696e+18 -8.601673e+18 Ambler Running running 106383175 149 1.659285e+12 9 private
3: 9305033616 5.784667e+17 -8.295883e+18 Ambler Walking walking 106383175 149 1.659202e+12 9 private
4: 9296749083 -6.688525e+17 -7.950984e+18 Ambler Running running 106383175 149 1.659094e+12 9 private

You’ll get an error like so, which seems to be ok:

Warning message:
In data.table::rbindlist(read_json(filename)[[1]]$summarizedActivitiesExport, :
Column 40 [‘summarizedDiveInfo’] of item 1 is length 0. This (and 8 others like it) has been filled with NA (NULL for list columns) to make each item uniform.