0

Getting "JSONDecodeError: Expecting value: line 1 column 1 (char 0)" error when I try to read the Twitter streaming data I downloaded using Stream and saving in txt format.

Have tried various changes to the codes as suggesting in similar questions but none worked.

If I remove (errors='ignore') from open, I am getting the following error UnicodeDecodeError

# String of path to file: tweets_data_path
tweets_data_path = 'Tweets.txt'

# Initialize empty list to store tweets: tweets_data
tweets_data = []

# Open connection to file
tweets_file = open(tweets_data_path, "r", errors='ignore') 

# Read in tweets and store in list: tweets_data
for line in tweets_file:
    if line.strip():
        tweets_data.append(json.loads(line))

# Close connection to file
tweets_file.close()

I am getting "JSONDecodeError: Expecting value: line 1 column 1 (char 0)" error when I run the above line of codes in Jupyter notebook.

cullzie
  • 2,705
  • 2
  • 16
  • 21
  • try to `print(line)` and see if it really is json type string – nickanor Mar 25 '19 at 02:14
  • Thanks for the response. When I print lines I am getting these characters as well "यह कहना अभिमानपूरà¥à¤£ होगा कि मैं देश का PM बनूंगा, फैसला चà¥à¤¨à¤¾à¤µ बाद होगा: à¤"°à¤¾à¤¹à¥à¤² गांधी" which I think is in Hindi – Chirag Srinivas Mar 25 '19 at 02:29
  • thats the reason why decode errors. you need to add the right encoding i guess – nickanor Mar 25 '19 at 06:31
  • Your code assume that each line in the file is a valid JSON string. In order to be a valid JSON string the line first char must be '[' or '{'. What is the first char in your lines? How was this file created? – balderman Mar 25 '19 at 09:48
  • Are you sure each line of `tweets.txt` is supposed to be valid json all on its own? json files aren't usually arranged that way. – John Gordon Mar 25 '19 at 23:55

0 Answers0