Published
Edited
Apr 3, 2019
Insert cell
Insert cell
Insert cell
twitterResponses = "https://gist.githubusercontent.com/cesandoval/ca0310352cc98742fc846e6a86a80c04/raw/0a591c6b7c4316235601b5a809df854f939418f2/twitter_response.json"
Insert cell
//use d3 to load the JSON
tweets = d3.json(twitterResponses)
Insert cell
Insert cell
//use the key (statuses) to access
statuses = tweets.statuses
Insert cell
//access the specific element of the statuses (which is an array)
//It is important to get familiar with the object/ array format of the data of interest
//use [x] to access the element in an array
//use .x to access the element in an object based on keys
tweets.statuses[0]
Insert cell
tweets.statuses[0].geo
Insert cell
tweets.statuses[0].user.id
Insert cell
searchMetadata = tweets.search_metadata
Insert cell
Insert cell
statuses[0]
Insert cell
Insert cell
text = statuses[0].text
Insert cell
textId = statuses[0].id
Insert cell
Insert cell
userId = statuses[0].user.id
Insert cell
userName = statuses[0].user.name
Insert cell
Insert cell
{
let texts = []
for (let i in statuses) {
// we can easily loop through the elements in an array
let currentText = statuses[i].text
texts.push(currentText)
}
return texts
}
Insert cell
// get the tweets IDs as an array
{
let emptyArray = []
for (let i in statuses) {
// we can easily loop through the elements in an array
let currentArray = statuses[i]
let tweetId=statuses[i].id
emptyArray.push(tweetId)
}
return emptyArray
}
Insert cell
Insert cell
// Your code here
{
let emptyObject = {}
let emptyArray = []
for (let i in statuses) {
let currentTweetId=statuses[i].id
let currentTweetText=statuses[i].text
emptyObject[currentTweetId]=currentTweetText
}
return emptyObject
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more