Trying to make a script to read this json file and I having some erros while trying it.
urllib.request.urlopen("https://github.com/lutangar/cities.json/blob/master/cities.json") as url: data = json.load(url) print(data)
When I try to run, I'm having this error and I don't know how to fix it.
JSONDecodeError: Expecting value: line 8 column 1 (char 7)
I'm trying to open the link but I alwasy got an error message.
CodePudding user response:
Add ?raw=true
to the URL:
import urllib.request
with urllib.request.urlopen(
"https://github.com/lutangar/cities.json/blob/master/cities.json?raw=true"
) as u:
data = json.load(u)
print(data)
Prints:
[{'country': 'AD', 'name': 'Sant Julià de Lòria', 'lat': '42.46372', 'lng': '1.49129'}, {'country': 'AD', 'name': 'Pas de la Casa', 'lat': '42.54277', 'lng': '1.73361'}, {'country': 'AD', 'name': 'Ordino', 'lat': '42.55623', 'lng': ...