I'm having a problem with some json file (generated from Twython / Tweeter API).
The file looks like this:
[
{
"created_at": "Thu Mar 14 20:24:53 +0000 2019",
"id": 1106290123426140165,
"id_str": "1106290123426140165",
"text": "RT @ALABDULLATIF: n@B_Al3bdullatif \n\u278b\u2026",
"source": "<a href=\"http://twitter.com/download/android\"
rel=\"nofollow\">Twitter for Android</a>",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 1091414851400929286,
"id_str": "1091414851400929286",
"name": "u064a",
"screen_name": "UThbZ4nwsuzAMQm",
"location": null,
"url": null,
"description": null,
"translator_type": "none",
"protected": false,
"verified": false,
"followers_count": 0,
"friends_count": 0,
"listed_count": 0,
"favourites_count": 0,
"statuses_count": 2,
"created_at": "Fri Feb 01 19:15:52 +0000 2019",
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "F5F8FA",
ETC
When I try to read it with this:
fname = "tweets_03.json"
text=[]
retweets=[]
language=[]
followers=[]
with open(fname, 'r') as f:
for line in f:
if not line.isspace():
tweet = json.loads(line)
text.append(tweet.get('text', ''))
retweets.append(tweet.get('retweet_count',''))
language.append(tweet.get('lang',''))
followers.append(tweet.get('followers_count',''))
text=pd.DataFrame(text)
text.columns=['text']
retweets=pd.DataFrame(retweets)
retweets.columns=['retweets']
language=pd.DataFrame(language)
language.columns=['language']
followers=pd.DataFrame(followers)
followers.columns=['followers']
df=pd.concat([text,retweets,language,followers],axis=1)
df.head(5)
I get the following error msg:
JSONDecodeError: Expecting value: line 2 column 1 (char 2)
I also tried:
data = "tweets_03.json"
jdata = json.loads(data)
df = pd.DataFrame(jdata)
and that gives me the following error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
If anyone could pse help it would be much appreciated. I'm wanting to convert the data into a dataframe. Thank you Best Wishes