Instructions

The New York Times web site provides a rich set of APIs, as described here: http://developer.nytimes.com/docs You’ll need to start by signing up for an API key. Your task is to choose one of the New York Times APIs, construct an interface in R to read in the JSON data, and transform it to an R dataframe.

Load API data

Data is loaded from the web api. The information being read are the 20 best sellers books registered by NYtimes api.

link2 <- "https://api.nytimes.com/svc/books/v3/lists/best-sellers/history.json?api-key=G1cUkg2rCJr5xWog5sRRnePn1JTtUBCZ"

booksDT <- getURL(link2)

Reading Data

The data is read and converted from json to a list.

bookl <- booksDT %>% fromJSON(simplifyVector = FALSE)
bookList <- bookl$results 

Preparing Dataframe

#getting the headers names from list name
headers <- bookList[[1]] %>% unlist() %>% names()
headers <- headers[1:8] %>% as.list()

#empty dataframe for storing json data. This dataframe will have 8 columns.
books <- data.frame(matrix(ncol = 8))
names(books) <- headers


#data is processed and stored in the dataframe
for (i in 1:20) {
  bo <- bookList[[i]][1:8] %>% unlist() %>% as.vector()
  books <- rbind(books,bo)
}

Data Display

books %>% na.omit %>% kable() %>% 
kable_styling()
title description contributor author contributor_note price age_group publisher
2 “I GIVE YOU MY BODY …” The author of the Outlander novels gives tips on writing sex scenes, drawing on examples from the books. by Diana Gabaldon Diana Gabaldon 0 Dell
3 “MOST BLESSED OF THE PATRIARCHS” A character study that attempts to make sense of Jefferson’s contradictions. by Annette Gordon-Reed and Peter S. Onuf Annette Gordon-Reed and Peter S Onuf 0 Liveright
4 #ASKGARYVEE The entrepreneur expands on subjects addressed on his Internet show, like marketing, management and social media. by Gary Vaynerchuk Gary Vaynerchuk 0 HarperCollins
5 #GIRLBOSS An online fashion retailer traces her path to success. by Sophia Amoruso Sophia Amoruso 0 Portfolio/Penguin/Putnam
6 #NEVERAGAIN Students from Marjory Stoneman Douglas High School describe the Valentine’s Day mass shooting and outline ways to prevent similar incidents. by David Hogg and Lauren Hogg David Hogg and Lauren Hogg 0 Random House
7 $100 STARTUP How to build a profitable start up for $100 or less and be your own boss. by Chris Guillebeau Chris Guillebeau 23 Crown Business
8 $20 PER GALLON by Christopher Steiner Christopher Steiner 0 Grand Central
9 ’57, Chicago Steve Monroe 0 ’57, Chicago Steve Monroe 0 ’57, Chicago Steve Monroe
10 ‘ROCK OF AGES:’‘ROLLING STONE’‘HISTORY OF ROCK AND ROLL’ GEOFFREY STOKES, KEN TUCKER’ ’ED WARD 0 ‘ROCK OF AGES:’‘ROLLING STONE’‘HISTORY OF ROCK AND ROLL’ GEOFFREY STOKES, KEN TUCKER’ ’ED WARD 0 ‘ROCK OF AGES:’‘ROLLING STONE’‘HISTORY OF ROCK AND ROLL’ GEOFFREY STOKES, KEN TUCKER’ ’ED WARD
11 ‘THE HIGH ROAD TO CHINA: GEORGE BOGLE, THE PANCHEN LAMA AND THE FIRST BRITISH EXPEDITION TO TIBET’ KATE TELTSCHER 0 ‘THE HIGH ROAD TO CHINA: GEORGE BOGLE, THE PANCHEN LAMA AND THE FIRST BRITISH EXPEDITION TO TIBET’ KATE TELTSCHER 0 ‘THE HIGH ROAD TO CHINA: GEORGE BOGLE, THE PANCHEN LAMA AND THE FIRST BRITISH EXPEDITION TO TIBET’ KATE TELTSCHER
12 ’TIL DEATH by Sharon Sala Sharon Sala 0 Harlequin Mira
13 ’TIL DEATH DO US PART A matchmaker in Victorian England turns to a crime novelist for help when she starts receiving a series of disturbingly personalized trinkets. by Amanda Quick Amanda Quick 0 Berkley
14 ’Til Faith Do Us Part: How Interfaith Marriage is Transforming America Naomi Schaefer Riley 0 ’Til Faith Do Us Part: How Interfaith Marriage is Transforming America Naomi Schaefer Riley 0 ’Til Faith Do Us Part: How Interfaith Marriage is Transforming America Naomi Schaefer Riley
15 ’TIS THE SEASON Two classic holiday stories — “Under the Christmas Tree” (2009) and “Midnight Confessions” (2010) — plus the novella “Backward Glance” (1991). by Robyn Carr Ron Carr 0 Harlequin Mira
16 ——, THAT’S DELICIOUS by Action Bronson with Rachel Wharton Action Bronson with Rachel Wharton 0 Abrams
17 …and the Horse He Rode In On: The People V. Kenneth Starr James Carville 0 …and the Horse He Rode In On: The People V. Kenneth Starr James Carville 0 …and the Horse He Rode In On: The People V. Kenneth Starr James Carville
18 .HACK G.U. , VOL. 5 This series, set in the future, is about an online, multiplayer game run amok. This volume concludes the tale. by Hamazaki Tatsuya Hamazaki Tatsuya 10.99 TOKYOPOP
19 1 Ragged Ridge Road David Adams Richards 0 1 Ragged Ridge Road David Adams Richards 0 1 Ragged Ridge Road David Adams Richards
20 1,000 PLACES TO SEE BEFORE YOU DIE A guide for traveling the world; second edition updated with new entries. by Patricia Schultz Patricia Schultz 0 Workman
21 1,000 RECORDINGS TO HEAR BEFORE YOU DIE Operas, rock albums, blues, classical music, world music and other essentials, from a musician and music journalist. by Tom Moon Tom Moon 0 Workman