I have a code:
dguid='2016A0011M4B'
income='7'
ethnic='3'
language='10'
url = 'https://www12.statcan.gc.ca/rest/census-recensement/CPR2016.json?lang=E&dguid={}&topic={}¬es=1'.format(
dguid,
ethnic)
!wget -q -O 'data.json' url
with open('data.json') as json_data:
data = json.load(json_data)
It gives me an Error enter image description here
--------------------------------------------------------------------------- JSONDecodeError Traceback (most recent call last) in () 9 get_ipython().system("wget -q -O 'data.json' url") 10 with open('data.json') as json_data: ---> 11 data = json.load(json_data)
/opt/conda/envs/DSX-Python35/lib/python3.5/json/init.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 266 cls=cls, object_hook=object_hook, 267 parse_float=parse_float, parse_int=parse_int, --> 268 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw) 269 270
/opt/conda/envs/DSX-Python35/lib/python3.5/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 317 parse_int is None and parse_float is None and 318 parse_constant is None and object_pairs_hook is None and not kw): --> 319 return _default_decoder.decode(s) 320 if cls is None: 321 cls = JSONDecoder
/opt/conda/envs/DSX-Python35/lib/python3.5/json/decoder.py in decode(self, s, _w) 337 338 """ --> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 340 end = _w(s, end).end() 341 if end != len(s):
/opt/conda/envs/DSX-Python35/lib/python3.5/json/decoder.py in raw_decode(self, s, idx) 355 obj, end = self.scan_once(s, idx) 356 except StopIteration as err: --> 357 raise JSONDecodeError("Expecting value", s, err.value) from None 358 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
what is wrong?
!wget -q -O 'data.json' url
does not look like valid Python code... – Ralf