The Twitter API methods return JSON objects. JSON (JavaScript Object Notation) is a text-based data-interchange format used to represent objects as collections of name–value pairs. It’s commonly used when invoking web services. JSON is both a human-readable and computer-readable format that makes data easy to send and receive across the Internet.
JSON objects are similar to Python dictionaries. Each JSON object contains a list of property names and values, in the following curly braced format:
{propertyName1: value1, propertyName2: value2}
As in Python, JSON lists are comma-separated values in square brackets:
[value1, value2, value3]
For your convenience, Tweepy handles the JSON for you behind the scenes, converting JSON to Python objects using classes defined in the Tweepy library.
A tweet (also called a status update) may contain a maximum of 280 characters, but the tweet objects returned by the Twitter APIs contain many metadata attributes that describe aspects of the tweet, such as:
when it was created,
who created it,
lists of the hashtags, urls, @-mentions and media (such as images and videos, which are specified via their URLs) included in the tweet,
and more.
The following table lists a few key attributes of a tweet object:
Let’s look at sample JSON for the following tweet from the @nasa
account:
@NoFear1075 Great question, Anthony! Throughout its seven-year mission,
our Parker #SolarProbe spacecraft... https://t.co/xKd6ym8waT'
We added line numbers and reformatted some of the JSON due to wrapping. Note that some fields in Tweet JSON are not supported in every Twitter API method; such differences are explained in the online documentation for each method.
1 {'created_at': 'Wed Sep 05 18:19:34 +0000 2018',
2 'id': 1037404890354606082,
3 'id_str': '1037404890354606082',
4 'text': '@NoFear1075 Great question, Anthony! Throughout its seven-year
mission, our Parker #SolarProbe spacecraft… https://t.co/xKd6ym8waT',
5 'truncated': True,
6 'entities': {'hashtags': [{'text': 'SolarProbe', 'indices': [84, 95]}],
7 'symbols': [],
8 'user_mentions': [{'screen_name': 'NoFear1075',
9 'name': 'Anthony Perrone',
10 'id': 284339791,
11 'id_str': '284339791',
12 'indices': [0, 11]}],
13 'urls': [{'url': 'https://t.co/xKd6ym8waT',
14 'expanded_url': 'https://twitter.com/i/web/status/
1037404890354606082',
15 'display_url': 'twitter.com/i/web/status/1…',
16 'indices': [117, 140]}]},
17 'source': '<a href="http://twitter.com" rel="nofollow">Twitter Web
Client</a>',
18 'in_reply_to_status_id': 1037390542424956928,
19 'in_reply_to_status_id_str': '1037390542424956928',
20 'in_reply_to_user_id': 284339791,
21 'in_reply_to_user_id_str': '284339791',
22 'in_reply_to_screen_name': 'NoFear1075',
23 'user': {'id': 11348282,
24 'id_str': '11348282',
25 'name': 'NASA',
26 'screen_name': 'NASA',
27 'location': '',
28 'description': 'Explore the universe and discover our home planet with
@NASA. We usually post in EST (UTC-5)',
29 'url': 'https://t.co/TcEE6NS8nD',
30 'entities': {'url': {'urls': [{'url': 'https://t.co/TcEE6NS8nD',
31 'expanded_url': 'http://www.nasa.gov',
32 'display_url': 'nasa.gov',
33 'indices': [0, 23]}]},
34 'description': {'urls': []}},
35 'protected': False,
36 'followers_count': 29486081,
37 'friends_count': 287,
38 'listed_count': 91928,
39 'created_at': 'Wed Dec 19 20:20:32 +0000 2007',
40 'favourites_count': 3963,
41 'time_zone': None,
42 'geo_enabled': False,
43 'verified': True,
44 'statuses_count': 53147,
45 'lang': 'en',
46 'contributors_enabled': False,
47 'is_translator': False,
48 'is_translation_enabled': False,
49 'profile_background_color': '000000',
50 'profile_background_image_url': 'http://abs.twimg.com/images/themes/
theme1/bg.png',
51 'profile_background_image_url_https': 'https://abs.twimg.com/images/
themes/theme1/bg.png',
52 'profile_image_url': 'http://pbs.twimg.com/profile_images/188302352/
nasalogo_twitter_normal.jpg',
53 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/
188302352/nasalogo_twitter_normal.jpg',
54 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/11348282/
1535145490',
55 'profile_link_color': '205BA7',
56 'profile_sidebar_border_color': '000000',
57 'profile_sidebar_fill_color': 'F3F2F2',
58 'profile_text_color': '000000',
59 'profile_use_background_image': True,
60 'has_extended_profile': True,
61 'default_profile': False,
62 'default_profile_image': False,
63 'following': True,
64 'follow_request_sent': False,
65 'notifications': False,
66 'translator_type': 'regular'},
67 'geo': None,
68 'coordinates': None,
69 'place': None,
70 'contributors': None,
71 'is_quote_status': False,
72 'retweet_count': 7,
73 'favorite_count': 19,
74 'favorited': False,
75 'retweeted': False,
76 'possibly_sensitive': False,
77 'lang': 'en'}
For a complete, more readable list of the tweet object attributes, see:
https:/ / developer.twitter.com/ en/ docs/ tweets/ data-dictionary/ overview/ tweet-object.html
For additional details that were added when Twitter moved from a limit of 140 to 280 characters per tweet, see
https:/ / developer.twitter.com/ en/ docs/ tweets/ data-dictionary/ overview/ intro-to-tweet-json.html#extendedtweet
For a general overview of all the JSON objects that Twitter APIs return, and links to the specific object details, see
https:/ / developer.twitter.com/ en/ docs/ tweets/ data-dictionary/ overview/ intro-to-tweet-json
(Fill-In) Tweet objects returned by the Twitter APIs contain many attributes that describe aspects of the tweet.
Answer: metadata.
(True/False) JSON is both a human-readable and computer-readable format that makes objects easy to send and receive across the Internet.
Answer: True.