George
George

Reputation: 41

JSONDecodeError: Expecting value: line 7 column 1 (char 6) - when i use json.load() method

I am working in Google Colab. I use the json.load() method to create a dictionary from a json file. The code is:

import json

! wget -O train_set.json https://github.com/rslab-ntua/MSc_GBDA/blob/master/2020/Exercise_ML2/train_split.json

with open('train_set.json') as f:
  train_set = json.load(f)

I get the following error:

---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
<ipython-input-20-1a34dc9ec442> in <module>()
      4 
      5 with open('train_set.json') as f:
----> 6   train_set = json.load(f)

3 frames
/usr/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
    353             obj, end = self.scan_once(s, idx)
    354         except StopIteration as err:
--> 355             raise JSONDecodeError("Expecting value", s, err.value) from None
    356         return obj, end

JSONDecodeError: Expecting value: line 7 column 1 (char 6)

The first lines of the json file are: enter image description here

Why i have this message error?

Upvotes: 0

Views: 526

Answers (1)

Jonathan Leon
Jonathan Leon

Reputation: 5648

The url you are using gets you to the page that contains the data you want, however the data is in a different url. change 'blob' to 'raw'

r = requests.get('https://github.com/rslab-ntua/MSc_GBDA/raw/master/2020/Exercise_ML2/train_split.json').json()

print(r)

['2750/River/River_2132.jpg',
 '2750/HerbaceousVegetation/HerbaceousVegetation_868.jpg',
 '2750/Highway/Highway_316.jpg',
 '2750/Residential/Residential_2628.jpg',
 '2750/Industrial/Industrial_1304.jpg',
 '2750/AnnualCrop/AnnualCrop_1615.jpg',
 '2750/SeaLake/SeaLake_1227.jpg',
 '2750/SeaLake/SeaLake_677.jpg',
 '2750/Forest/Forest_2496.jpg',
 '2750/Forest/Forest_2532.jpg',....

Upvotes: 1

Related Questions