Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Strava JSON to GPX converter
### pip install gpxpy
import sys
import gpxpy
import gpxpy.gpx
import json
import datetime
def convert(f):
gpx = gpxpy.gpx.GPX()
# Create first track in our GPX:
gpx_track = gpxpy.gpx.GPXTrack()
# Create first segment in our GPX track:
gpx_segment = gpxpy.gpx.GPXTrackSegment()
# Create points:
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(2.1234, 5.1234, elevation=1234))
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(2.1235, 5.1235, elevation=1235))
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(2.1236, 5.1236, elevation=1236))
# You can add routes and waypoints, too...
with open(f) as json_data:
strava_json = json.load(json_data)
path_data = strava_json["data"]
for dp in path_data[0]["values"]:
time = dp[0]
pt = dp[1]
elevation = dp[2]
date = datetime.datetime.fromtimestamp(time)
point = gpxpy.gpx.GPXTrackPoint(latitude = pt[0], longitude = pt[1], time = date, elevation = elevation)
gpx_str = gpx.to_xml()
with open(f + ".gpx", "w") as target:
print "Done!"
if __name__ == "__main__":
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment