Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converts a Google Location JSON file into a CSV with Timestamp, Latitude, and Longitude.
import re
import json
import csv
JSON_data="C:/Users/JSON FILE PATH.txt"
CSV_file="C:/Users/CSV FILE PATH.csv"
with open(JSON_data) as f:
data = json.load(f)
csv_f=open(CSV_file, 'w')
for x in range(len(data["locations"])):
regex_Time=re.findall(".timestampMs.: .\d\d\d\d\d\d\d\d\d\d\d\d\d.", str(data["locations"][x]))
regex_Lat=re.findall(".latitude...: \d\d\d\d\d\d\d\d\d", str(data["locations"][x]))
regex_Long=re.findall(".longitude...: -\d\d\d\d\d\d\d\d\d", str(data["locations"][x]))
csv_f.write(regex_Time[0][16:-1] + "," + regex_Lat[0][14:] + "," + regex_Long[0][15:]+'\n')
csv_f.close
print('Done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.