Skip to content

Instantly share code, notes, and snippets.



Last active Apr 22, 2016
What would you like to do?
Converts the JSON format used by "Zombies Run!" to GPX which can be imported in Runtastic.
package main
import (
type zombiesLog struct {
Gps []struct {
Altitude float64 `json:"altitude"`
HorizontalAccuracy float64 `json:"horizontal_accuracy"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Time time.Time `json:"time"`
VerticalAccuracy float64 `json:"vertical_accuracy"`
} `json:"gps"`
StartTime time.Time `json:"start_time"`
type gpx struct {
Gpx struct {
Creator string `xml:"creator,attr"`
Version string `xml:"version,attr"`
Xsi string `xml:"xsi,attr"`
SchemaLocation string `xml:"schemaLocation,attr"`
Trk struct {
Name string `xml:"name"`
Trkseg struct {
Trkpt []trkPoints `xml:"trkpt"`
} `xml:"trkseg"`
} `xml:"trk"`
} `xml:"gpx"`
type trkPoints struct {
Lat string `xml:"lat,attr"`
Lon string `xml:"lon,attr"`
Ele string `xml:"ele"`
Time string `xml:"time"`
func main() {
// specify the input file as commandline argument
dat, err := os.Open(os.Args[1])
var zombiesJSON zombiesLog
err = json.NewDecoder(dat).Decode(&zombiesJSON)
var runtasticGPX gpx
// fill header values
runtasticGPX.Gpx.Creator = "zombies2gpx"
runtasticGPX.Gpx.Version = "1.0"
runtasticGPX.Gpx.SchemaLocation = ""
runtasticGPX.Gpx.Xsi = ""
// array for the trackpoints
runtasticPoints := make([]trkPoints, len(zombiesJSON.Gps))
// copy all trackpoints to the GPX xml stuct
for index, trackpoint := range zombiesJSON.Gps {
runtasticPoints[index] = trkPoints{
Lat: fmt.Sprintf("%f", trackpoint.Latitude),
Lon: fmt.Sprintf("%f", trackpoint.Longitude),
Ele: fmt.Sprintf("%f", trackpoint.Altitude),
Time: trackpoint.Time.Format(time.RFC3339),
runtasticGPX.Gpx.Trk.Trkseg.Trkpt = runtasticPoints
enc := xml.NewEncoder(os.Stdout)
enc.Indent(" ", " ")
err = enc.Encode(runtasticGPX)
func check(e error) {
if e != nil {

This comment has been minimized.

Copy link

@gregorstephen gregorstephen commented Feb 19, 2016

Great little tool! I've been looking for a way to extract the run logs out of the app, this (along with your blog post) was just what I needed - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment