knitr::opts_chunk$set(echo = TRUE)
# We need these packages
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.3
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(jsonlite)
## 
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
## 
##     flatten
library(knitr)

Overview: We are tasked with choosing one of the New York Times’s APIs to read in JSON data and transform it into an R dataframe.First we need to get an api key from link

Next we can use GET methods with the API

nyt_api_key = Sys.getenv("nyt_api_key")
q = paste("http://api.nytimes.com/svc/semantic/v2/concept/name/nytd_des/Baseball.json?fields=all&api-key=",nyt_api_key)
x = fromJSON(q, flatten=TRUE)
kable(x[5])
concept_id concept_name is_times_tag is_sensitive concept_status vernacular concept_type concept_created concept_updated concept_rule concept_gender taxonomy links search_api_query scope_notes combinations ancestors descendants article_list.results article_list.total
9944 Baseball 1 0 Active Baseball nytd_des 2009-10-28 14:30:04-04:00 2017-03-21 20:02:02-04:00 (OR,(START_1,_meta=“title”:“bats”),(OR,(START_5,_meta=“title”:“baseball”),(START_5,_meta=“title”:“mlb”),(START_5,_meta=“title”:“m.l.b.”)),(OR,_headline:“baseball”,_headline:“m.l.b.”,_headline:“yankees”,_headline:“mets”,_nyt_subsection:“baseball”,_subsection:“baseball”,_section:“baseball”,_nyt_section:“baseball”),(AND,(MINOC_3,“baseball”,“mets”,“m.l.b.”,“yankees”),(NOT,_tmac:“@Baseball (College)”)),(MIN_4,“at bat”,“at-bat”,“ball field”,“ball park”,“ball parks”,“ballpark”,“ballparks”,“baseball”,“bases loaded”,“bases-loaded”,“baseman”,“batting”,(OR,“bench coach”,“bench coaches”),“bottom of the ninth”,“bullpen”,(OR,“catcher”,“catchers”),(OR,“citifield”,“citi field”),“dugout”,“earned run average”,“fastball”,“fastballs”,“five-run”,“hitter”,“home run”,“homer”,“homered”,“infield”,“inning”,“innings”,“left-field”,“little league”,“off-speed pitch”,“outfield”,“outfielder”,“pickoff”,“pinch-hitter”,“pitch”,“pitches”,(OR,“pitcher”,“pitchers”),“pitching coach”,“pitching coaches”,“pitchout”,“reliever”,“right-field”,“shea stadium”,“slider”,“spring training”,“suicide squeeze”,“the majors”,“three-run”,“third-base”,“top of the ninth”,“two outs”,“two-run”,“first base”,“second base”,“third base”,“first baseman”,“second baseman”,“third baseman”,“world series”,“first-inning”,“second-inning”,“third-inning”,“fourth-inning”,“fifth-inning”,“sixth-inning”,“seventh-inning”,“eighth-inning”,“ninth-inning”,(OR,“negro league”,“negro leagues”,“negro leaguers”),“diamondbacks”,“braves”,“orioles”,“red sox”,“cubs”,“white sox”,“reds”,“indians”,“rockies”,“tigers”,“marlins”,“astros”,“royals”,“angels”,“dodgers”,“brewers”,“twins”,“mets”,“yankees”,“athletics”,“phillies”,“pirates”,“padres”,“giants”,“mariners”,“cardinals”,“devil rays”,“rangers”,“blue jays”,“nationals”,“bartolo colon”,“derek jeter”,“mo vaughn”,“theo epstein”,“george steinbrenner”,“yankee stadium”),(OR,“arizona diamondbacks”,“atlanta braves”,“baltimore orioles”,“boston red sox”,“chicago cubs”,“chicago white sox”,“cincinnati reds”,“cleveland indians”,“colorado rockies”,“detroit tigers”,“florida marlins”,“houston astros”,“kansas city royals”,“los angeles angels”,“los angeles dodgers”,“milwaukee brewers”,“minnesota twins”,“new york mets”,“new york yankees”,“oakland athletics”,“philadelphia phillies”,“pittsburgh pirates”,“san diego padres”,“san francisco giants”,“seattle mariners”,“st. louis cardinals”,“tampa bay devil rays”,“texas rangers”,“toronto blue jays”,“washington nationals”,“world baseball classic”),(DIST_25,“world series”,(OR,“game 1”,“game 2”,“game 3”,“game 4”,“game 5”,“game 6”,“game 7”,“game one”,“game two”,“game three”,“game four”,“game five”,“game six”,“game seven”))) NA list(source_concept_id = c(9944, 9944, 9944, 9944, 9944, 9944, 9944, 9944, 9944, 9944, 9944), target_concept_id = c(71320, 9684, 11560, 16744, 20528, 22256, 22268, 1469696, 16780, 69008, 16016), source_concept_name = c(“Baseball”, “Baseball”, “Baseball”, “Baseball”, “Baseball”, “Baseball”, “Baseball”, “Baseball”, “Baseball”, “Baseball”, “Baseball”), target_concept_name = c(“NCAA Baseball Championships”, “Athletics and Sports”, “College World Series”, “Minor Leagues”, “Stickball”, “World Baseball Classic”,
"World Series “,”Baseball (C ollege)“,”Mitc hell Report (Ba seball)“,”Cy You ng Award“,”L ittle League"), source_concept_type = c("ny td_des“,”nytd_des“,”nytd_d es“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“), target_concept_type = c(”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_org“), source_concept_vernacular = c(”Baseball“,”Baseball“,”Baseball“,”Baseball“,”Baseball",
“Baseball”, " Baseball“,”Bas eball“,”Baseba ll“,”Baseball" , “Baseball”), ta rget_concept_ vernacular = c( “NCAA Baseball”, “Sports”, " College World Series“,”Mino r league“,”Stickball“,”World Baseball Classic“,”World Series“,”None“,”Mitchell Report“,”Cy Young Award“,”Little League“), taxonomic_relation = c(”NT“,”BT“,”NT“,”NT“,”RT“,”NT“,”NT“,”NT“,”NT“,”NT“,”NT“), taxonomic_verification_status = c(”unverified“,”unverified“,”unverified“,”unverified“,”unverified“,”unverified“,”unverified",
“unverified”, “unverified”, “unverified”, " unverified")) list(concept_id = 9944, conce pt_name = "Base ball“, concept_status =”Act ive", is_times_tag = 1, conc ept_type = “nytd_des”, link_id = 1698852, relation = “sameAs”, link = “Baseball”, link_type = “wikipedia_raw_name”, mapping_type = "“) http://search-api.prd.iad1.nyt.net/svc/add/v1/sitesearch.json?fq=subject%3A%22Baseball%22&sort=newest&type=article%2Cblogpost&offset=0 list(scope_note =”Used for all coverage of professional, collegiate and recreational baseball.“, scope_note_name =”Baseball“, scope_note_type =”External“) list(combination_source_concept_id = 9944, combination_source_concept_name =”Baseball“, combination_source_concept_type =”nytd_des“, combination_target_concept_id = 11556, combination_target_concept_name =”College Athletics“, combination_target_concept_type =”nytd_des“, combination_note =”“) list(concept_id = 9684, concept_name =”Athletics and Sports“, is_times_tag = 1, concept_status =”Active“, vernacular =”Sports“, concept_type =”nytd_des“, concept_created =”2009-10-28 14:30:04-04:00“, concept_updated =”2019-12-03 15:07:02-05:00“) list(concept_id = c(11560, 16016, 16744, 16780, 22256, 22268, 69008, 71320, 1469696, 16020), concept_name = c(”College World Series“,”Little League“,”Minor Leagues“,”Mitchell Report (Baseball)“,”World Baseball Classic“,”World Series“,”Cy Young Award“,”NCAA Baseball Championships“,”Baseball (College)“,”Little League World Series“), is_times_tag = c(1, NA, 1, 1, 1, 1, 1, 1, 1, 1), concept_status = c(”Active“,”Deleted“,”Active“,”Active“,”Active“,”Active“,”Active“,”Active“,”Active",
“Active”), ve rnacular = c("C ollege World Se ries“,”Little League“,”Minor l eague“,”Mitc hell Report“,” World Baseball Classic“,”Wo rld Series“,”Cy Young Award “,”NCAA Baseball“, NA,”Little League World Series“), concept_type = c(”nytd_des“,”nytd_org“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“,”nytd_des“), concept_created = c(”2009-10-28 14:30:04-04:00“,”2009-10-28 14:30:04-04:00“,”2009-10-28 14:30:04-04:00“,”2009-10-28 14:30:04-04:00“,”2009-10-28 14:30:04-04:00",
"2009-10-28 1 4:30:04-04:00", "2010-10-01 15 :11:13-04:00", "2011-11-08 10:42 :24-05:00“,” 2014-03-14 10:2 8:01-04:00“,”2009-10-28 14: 30:04-04:00"), concept_updat ed = c(“2017-03-21 20:01:23-04:00”, “2014-07-29 18:13:58-04:00”, “2017-03-21 20:01:38-04:00”, “2017-03-21 20:01:49-04:00”, “2017-03-21 20:02:11-04:00”, “2017-03-21 20:01:31-04:00”, “2017-03-21 20:01:27-04:00”, “2017-03-21 20:01:58-04:00”, “2017-03-21 20:02:41-04:00”, “2017-03-21 20:02:10-04:00”)) list(body = c(“The deal addresses issues including players’ service time and free agency, and how to handle the postseason in case a shortened season can be played.”, “Just 5-foot-9 but packed with power, he was a mainstay of the Houston Astros’ lineup for 11 years in the 1960s and ’70s and a three-time All-Star.”, “The baseball draft could be drastically reduced in a deal cut with the players’ union to address complications of the game’s suspension.”, “Pursuing his dream of rebuilding the beloved ballpark, a die-hard follower found the stadium blueprints buried in a municipal subbasement.”,
"The deal wil l send masks to health profess ionals in the N ortheast with the distinctive pinstripes of t he Yankees and the Philadelp hia Phillies.“,”Complaints of baseball’s slow pace yielded to the universal wish that this game would last forever.“,”Instead of red, white and blue bunting and crowds flooding ballparks, we have players holed up in homes and endless questions about when baseball will return. When it does, it will be more important than ever.“,”A positive coronavirus test for a teammate meant every Yankees minor leaguer had to spend two weeks isolated in Florida. They got creative to keep busy and stay in shape.",
"The Library of Congress des ignates 25 reco rdings for pres ervation, in what it is billin g as “the ultim ate ‘stay at home’ playlist. ”“,”Syndergaard is expected to be out until midway through 2021 as he recovers from the operation.“), byline = c(”By The Associated Press“,”By The Associated Press“,”By Tyler Kepner“,”By John Freeman Gill“,”By David Waldstein“,”By Dan Barry“,”By Tyler Kepner“,”By James Wagner“,”By Jennifer Schuessler“,”By Kevin Armstrong“), date = c(”2020-03-27T23:13:07+0000",
"2020-03-27T2 2:45:23+0000", "2020-03-27T22: 40:40+0000“,”2 020-03-27T13:00:1 1+0000“,”202 0-03-26T19:37:5 6+0000“,”2020-03-26T18:00:1 2+0000“,”2020-03-26T09:00:3 7+0000“,”2020-03-25T22:30:55+0000“,”2020-03-25T07:00:09+0000“,”2020-03-25T00:02:28+0000“), document_type = c(”article“,”article“,”article“,”article“,”article“,”article“,”article“,”article“,”article“,”article“), title = c(”M.L.B. and Players’ Union Lay Out Framework to Navigate Suspended Season“,”Jimmy Wynn, ‘Toy Cannon’ Known for His Home Runs, Dies at 78",
"Future Playe rs Take a Big H it as M.L.B. Na vigates a Crisi s“,”A Brooklyn D odgers Fan Wh o Never Gave Up on Ebbets Field“,”Coronavi rus Protective Masks to Be M ade From M.L.B. Uniform Material“,”Baseball Season Opens With a Dash of Imagination“,”It’s Opening Day. Baseball Is Closed.“,”How the Yankees’ Minor Leaguers Spent 2 Weeks in Quarantine“,”Mister Rogers Song and Dr. Dre Added to National Recording Registry“,”Mets’ Noah Syndergaard Will Have Tommy John Surgery“), type_of_material = c(”News",
"Obituary (Ob it)“,”News“,” News“,”News", “News”, “News”, “News”, “News”, “News”), url = c("https://ww w.nytimes.com/2020/03/27/spo rts/baseball/baseball-union- deal.html“,”https://www.nytimes.com/2020/03/27/sports/baseball/jimmy-wynn-dead.html“,”https://www.nytimes.com/2020/03/27/sports/baseball/mlb-draft.html“,”https://www.nytimes.com/2020/03/27/realestate/a-brooklyn-dodgers-fan-who-never-gave-up-on-ebbets-field.html“,”https://www.nytimes.com/2020/03/26/sports/baseball/coronavirus-masks-gowns-mlb-uniforms.html",
"https://www. nytimes.com/202 0/03/26/sports/ baseball/baseba ll-opening-day-co ronavirus.htm l“,”https://ww w.nytimes.com/2020/03/26/spo rts/baseball/opening-day-mlb -virus.html“,”https://www.nytimes.com/2020/03/25/sports/baseball/yankees-quarantine-minor-leaguers.html“,”https://www.nytimes.com/2020/03/25/arts/dr-dre-mr-rogers-national-recording-registry-covid.html“,”https://www.nytimes.com/2020/03/24/sports/baseball/noah-syndergaard-tommy-john-surgery.html“), concepts.nytd_des = list(c(”Baseball“,”Coronavirus (2019-nCoV)"
), c("Deaths (Obituaries)", “Baseball”), c( “Baseball”, "Dr aft and Recruitme nt (Sports)", "Baseball (Col lege)“,”Minor Leagues“,”Co ronavirus (2019-nCoV)“), c(” Baseball“,”Stadiums and Arenas“,”Historic Buildings and Sites“,”ARCHIVES AND RECORDS“,”ARCHITECTURE“,”Models and Replicas“), c(”Protective Clothing and Gear“,”Uniforms“,”Baseball“,”Masks“,”Coronavirus (2019-nCoV)“), c(”Coronavirus (2019-nCoV)“,”Baseball“,”Shutdowns (Institutional)“), c(”Baseball“,”Seasons and Months“), c(”Baseball",
"Minor League s“,”Quarantine s“,”Coronaviru s (2019-nCoV)") , c("Audio Record ings, Downloa ds and Streamin g“,”Libraries and Librarian s“,”Pop and Rock Music“,”T elevision“,”Athletics and Sports“,”Baseball“,”Theater“), c(”Sports Injuries“,”Baseball“)), concepts.nytd_org = list(c(”Major League Baseball“,”Major League Baseball Players Assn“),”Houston Astros“,”Major League Baseball“, c(”Brooklyn Dodgers“,”Ebbets Field (Brooklyn, NY)“,”Municipal Archives (NYC)“), c(”Major League Baseball“,”New York Yankees",
"Philadelphia Phillies“),”M ajor League Bas eball“,”Major League Baseball", "New York Ya nkees“, c(”Libr ary of Congress“,”Village P eople (Music Group)“),”New York Mets“), concepts.nytd_per = list(NULL,”WYNN, JIMMY“, NULL,”KENNEDY, ROD JR“, c(”Manfred, Robert D“,”Rubin, Michael G“,”Wolf, Thomas W“), NULL,”Hornsby, Rogers“, NULL, c(”Dr Dre (1965- )“,”Rogers, Fred“),”Syndergaard, Noah“), concepts.nytd_geo = list(NULL, NULL, NULL,”Brooklyn (NYC)", NULL, NULL, NULL, NULL, NULL, NULL), concepts.nytd_ttl = list(
NULL, NUL L, NULL, NULL, NULL, NULL, NUL L, NULL, c("Mis ter Rogers’ Neigh borhood (TV P rogram)“,”Y.M. C.A. (Song)“,”Fiddler on th e Roof (Play)"), NULL)) 109688

Conclusions: We are able to use the NYT API to query data and read into R dataframes. It looks like the semantic API is not straightforward to interpret, nor is it obvious to see how the data may need to be tidied.