Understanding Twitter JSON

Analyzing Social Media Data in Python

Alex Hanna

Computational Social Scientist

Contents of Twitter JSON

{  "created_at": "Thu Apr 19 14:25:04 +0000 2018",
   "id": 986973961295720449,
   "id_str": "986973961295720449",
   "text": "Writing out the script of my @DataCamp class 
            and I can't help but mentally read it back to myself in 
            @hugobowne's voice.",    
   "retweet_count": 0,
   "favorite_count": 1,
      ...  }
  • How many retweets, favorites
  • Language
  • Reply to which tweet
  • Reply to which user
Analyzing Social Media Data in Python

Child JSON objects

{
        "user": {
            "id": 661613,
            "name": "Alex Hanna, Data Witch",
            "screen_name": "alexhanna",
            "location": "Toronto, ON",
            ...
         }
}
Analyzing Social Media Data in Python

Places, retweets/quoted tweets, and 140+ tweets

  • place and coordinate
    • contain geolocation
  • extended_tweet
    • tweets over 140 characters
  • retweeted_status and quoted_status
    • contain all tweet information of retweets and quoted tweets
Analyzing Social Media Data in Python

Accessing JSON

import json

tweet_json = open('tweet-example.json', 'r').read()

tweet = json.loads(tweet_json)
tweet['text']
Analyzing Social Media Data in Python

Child tweet JSON

tweet['user']['screen_name']

tweet['user']['name']
tweet['user']['created_at']
Analyzing Social Media Data in Python

Let's practice!

Analyzing Social Media Data in Python

Preparing Video For Download...