jackbillstrom
8/11/2013 - 10:00 PM

Converts a *.kml file to *.json, removes height. Working on to switch places with arrays. Python 3.3.2

Converts a *.kml file to *.json, removes height. Working on to switch places with arrays. Python 3.3.2

#!/usr/bin/python

import simplejson as json, re
print ("KML to JSON")
filename = input("Select file: ")
outputFile = input("Desired filename for output: ")
fileObj = open(outputFile + ".json","w")
output = (json.dumps(dict( (entry[0].strip(), entry[1].strip())
         for entry in re.findall('<name>(.*?)</name>.*?<coordinates>(.*?)</coordinates>(?s)', open(filename + ".kml").read() ) )))
clean1 = output.replace(",0 ",",")
cleanFinal = clean1.replace(',0"','"')
fileObj.write(cleanFinal)
fileObj.close()
print ("File saved!")