###Introduction - New York Times API For this assignment, I enabled the Books, Movies and top stories NYT API to explore data. To prepare for this, I created an account and generated an authorization key to be able to request data from NYT servers.


Loading Libraries

The library to read and load the NYT API data, in JSON format, is jsonlite. Once read as a dataframe, tidy verse cleanup can be applied for further data exploration.

library(jsonlite)


Books & Popular Article API

There are two API requests I made. The first returns the best sellers by type (hardcover, paperback, etc) from the Book List. The second API request performed a query for Anne Rice books (since a family recently mentioned her book was turned into a series) from Book Reviews. Both were read as data frames.

#Reads the Book list API request and reads it into a dataframe.
best_seller_types <- fromJSON(paste0("http://api.nytimes.com/svc/books/v3/lists/names.json?api-key=",NYT_Key))
best_seller_types <- best_seller_types$results
class(best_seller_types)
## [1] "data.frame"
knitr::kable(head(best_seller_types, n=3))
list_name display_name list_name_encoded oldest_published_date newest_published_date updated
Combined Print and E-Book Fiction Combined Print & E-Book Fiction combined-print-and-e-book-fiction 2011-02-13 2022-11-06 WEEKLY
Combined Print and E-Book Nonfiction Combined Print & E-Book Nonfiction combined-print-and-e-book-nonfiction 2011-02-13 2022-11-06 WEEKLY
Hardcover Fiction Hardcover Fiction hardcover-fiction 2008-06-08 2022-11-06 WEEKLY
# Reads the Reviews API request for Anne Rice Books and read it into a date frame.
Rice_Books<-fromJSON(paste0("https://api.nytimes.com/svc/books/v3/reviews.json?author=Anne+Rice&api-key=",NYT_Key))
Rice_Books<-Rice_Books$results
class(Rice_Books)
## [1] "data.frame"
knitr::kable(head(Rice_Books, n=2))
url publication_dt byline book_title book_author summary uuid uri isbn13
http://www.nytimes.com/1998/12/20/books/books-in-brief-fiction-375268.html 1998-12-20 MICHAEL PORTER Vampire Armand Anne Rice 00000000-0000-0000-0000-000000000000 nyt://book/00000000-0000-0000-0000-000000000000 9781407099699
http://www.nytimes.com/2000/10/26/books/books-of-the-times-so-bewitched-why-he-feels-almost-human.html 2000-10-26 JANET MASLIN Merrick Anne Rice 00000000-0000-0000-0000-000000000000 nyt://book/00000000-0000-0000-0000-000000000000 9780345422408
# Reads the Popular Articles API request for those shared on Facebook.
FB_PopArticles<-fromJSON(paste0("https://api.nytimes.com/svc/mostpopular/v2/shared/1/facebook.json?api-key=",NYT_Key), flatten = TRUE)
FB_PopArticles<-FB_PopArticles$results
class(FB_PopArticles)
## [1] "data.frame"
knitr::kable(head(FB_PopArticles, n=2))
uri url id asset_id source published_date updated section subsection nytdsection adx_keywords column byline type title abstract des_facet org_facet per_facet geo_facet media eta_id
nyt://article/1aa8c7ea-76d6-513b-85e1-d9d78281c766 https://www.nytimes.com/2022/10/28/sports/football/tom-brady-gisele-bundchen-divorce.html 100000008568007 100000008568007 New York Times 2022-10-28 2022-10-30 13:00:55 Sports N.F.L. sports Divorce, Separations and Annulments;Football;Fashion and Apparel;Celebrities;Brady, Tom;Bundchen, Gisele;Tampa Bay Buccaneers;National Football League NA By Jesus Jiménez and Kevin Draper Article Tom Brady and Gisele Bündchen Divorce After 13 Years The closely watched celebrity couple announced their split on Instagram and filed their divorce agreement in a Florida court. Divorce, Separations and Annulments, Football , Fashion and Apparel , Celebrities Tampa Bay Buccaneers , National Football League Brady, Tom , Bundchen, Gisele image , photo , Gisele Bündchen and Tom Brady after the Super Bowl in February 2021, which Brady won with the Tampa Bay Buccaneers. , Steve Luciano/Associated Press , 1 , https://static01.nyt.com/images/2022/10/28/sports/00HFObrady-gisele-divorce/00HFObrady-gisele-divorce-thumbStandard.jpg , https://static01.nyt.com/images/2022/10/28/sports/00HFObrady-gisele-divorce/merlin_183473928_3bef01e1-7341-46c9-97fc-a633e266e229-mediumThreeByTwo210.jpg, https://static01.nyt.com/images/2022/10/28/sports/00HFObrady-gisele-divorce/merlin_183473928_3bef01e1-7341-46c9-97fc-a633e266e229-mediumThreeByTwo440.jpg, Standard Thumbnail , mediumThreeByTwo210 , mediumThreeByTwo440 , 75 , 140 , 293 , 75 , 210 , 440 0
nyt://article/d8ffd17c-4e39-5d23-85e7-1c7a22bbd691 https://www.nytimes.com/2022/10/29/us/politics/paul-pelosi-political-violence.html 100000008606291 100000008606291 New York Times 2022-10-29 2022-10-30 13:02:03 U.S. Politics u.s. United States Politics and Government;Threats and Threatening Messages;Assaults;Rumors and Misinformation;Conspiracy Theories;Storming of the US Capitol (Jan, 2021);Fringe Groups and Movements;Right-Wing Extremism and Alt-Right;Pelosi, Nancy;Pelosi, Paul;House of Representatives;Senate;Democratic Party;Republican Party NA By Catie Edmondson Article Pelosi Attack Highlights Rising Fears of Political Violence The assault of the House speaker’s husband inside their home comes as threats against members of Congress have increased in recent years. United States Politics and Government , Threats and Threatening Messages , Assaults , Rumors and Misinformation , Conspiracy Theories , Storming of the US Capitol (Jan, 2021), Fringe Groups and Movements , Right-Wing Extremism and Alt-Right House of Representatives, Senate , Democratic Party , Republican Party Pelosi, Nancy, Pelosi, Paul image , photo , Security personnel standing guard while Representative Steve Scalise, Republican of Louisiana, was speaking on the steps of the Capitol last year. Mr. Scalise was shot in 2017 by a man with a grudge against Republicans. , Andrew Harnik/Associated Press , 1 , https://static01.nyt.com/images/2022/10/29/multimedia/29dc-cong-threats-01-1-7734/29dc-cong-threats-01-1-7734-thumbStandard.jpg , https://static01.nyt.com/images/2022/10/29/multimedia/29dc-cong-threats-01-1-7734/29dc-cong-threats-01-1-7734-mediumThreeByTwo210.jpg , https://static01.nyt.com/images/2022/10/29/multimedia/29dc-cong-threats-01-1-7734/29dc-cong-threats-01-1-7734-mediumThreeByTwo440.jpg , Standard Thumbnail , mediumThreeByTwo210 , mediumThreeByTwo440 , 75 , 140 , 293 , 75 , 210 , 440 0


Conclusion

jsonlite reads JSON files well when well structured. The automatic conversion into a relatively clean dataframe allow for easier cleanup and further exploration. The above dataframes, date columns can be be converted from the characters values, columns can be split for further analysis or additional regex string matches can be made.