Last active
February 9, 2020 07:39
-
-
Save compustar/5168e084c83b2732b62842e489f59b57 to your computer and use it in GitHub Desktop.
Python script parses Google Map JSON and convert it to Excel parsable JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def get_layers(data): | |
return data[1][6] | |
def get_items(data): | |
return data[12][0][13][0] | |
def parse_item(item): | |
output = {"latitude": item[1][0][0][0], | |
"longitude": item[1][0][0][1]} | |
output[item[5][0][0]] = item[5][0][1][0] | |
for a in item[5][3]: | |
output[a[0]] =a[1][0] | |
return output | |
if __name__ == "__main__": | |
f = open("data.json", "r", encoding="utf8") | |
data = f.read() | |
f.close() | |
data = json.loads(data) | |
layers = get_layers(data) | |
items = get_items(layers[-1]) | |
items = [parse_item(x) for x in items] | |
output = json.dumps(items) | |
f = open("data_.json", "w", encoding="utf8") | |
f.write(output) | |
f.flush() | |
f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment