1

I am getting this error while importing a JSON dataset from a website.

JSONDecodeError: Expecting value: line 1 column 2 (char 1)

I am working in colaboratory and wanted to import the sarcastic dataset, but since I don't know JSON, I am stuck. I have tried different placements of slash() character and also changing the -o parameter but nothing works correctly...my code[reprex]:=====>

!wget --no-check-certificate \ https://storage.googleapis.com/laurencemoroney-blog.appspot.com/sarcasm.json -o /tmp/sarcasm.json

import json
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences

#importing the Sarcasm dataset from !wget --no-check-certificate \ https://storage.googleapis.com/laurencemoroney-blog.appspot.com/sarcasm.json \ 
#-o /tmp/sarcasm.json

with open("/tmp/sarcasm.json", 'r') as f:
  datastore = json.load(f)
  datastore = json.detect_encoding()
  print (datastore)
sentences = []
labels = []
urls = []

I think the problem might be the fact the the data is being imported in HTML format, which has to be converted in JSON format(or something compatible with it). Any help would be appreciated! :)

4 Answers 4

1

In my case, i was able to resolve this by replacing single quotes with double quotes.

a = "['1','2']"

json.loads(a.replace("'",'"'))

0

I suspect you are saving the log of the transaction(instead of the doc itself) to /tmp/sarcasm.json.

Try --output-document=sarcasm.json instead

wget --no-check-certificate "https://storage.googleapis.com/laurencemoroney-blog.appspot.com/sarcasm.json" --output-document=sarcasm.json
0

There is no need to detect the encoding, json library will take care of it

Remove the below line and try,

datastore = json.detect_encoding()
0

try using -O instead of -o

!wget --no-check-certificate \
    https://storage.googleapis.com/laurencemoroney-blog.appspot.com/sarcasm.json -O /tmp/sarcasm.json

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.