import json from html import escape with open('data.json') as data_file: data = json.load(data_file) with open('Megaliths.gpx', 'w') as gpx_file: gpx_file.write(''' Megalith sites Jude Southworth ''') for poi in data: gpx_file.write( ''' {} {} {} '''.format(poi['lat'], poi['lng'], escape(poi['name']), poi['type'], poi['url']) ) gpx_file.write('')