Content
We then use the jsonlite package to transform the books json file into a dataframe. There is a nested json column, “isbns”, that contains various types of isbns. We expand that column and then select relevent columns to preview the data.
json <- content(response, as="text")
res <- jsonlite::fromJSON(json)
books <- res[["results"]][["books"]]
colnames(books)## [1] "rank" "rank_last_week" "weeks_on_list"
## [4] "asterisk" "dagger" "primary_isbn10"
## [7] "primary_isbn13" "publisher" "description"
## [10] "price" "title" "author"
## [13] "contributor" "contributor_note" "book_image"
## [16] "book_image_width" "book_image_height" "amazon_product_url"
## [19] "age_group" "book_review_link" "first_chapter_link"
## [22] "sunday_review_link" "article_chapter_link" "isbns"
## [25] "buy_links"
books$isbn10 <- books %>% select("isbns") %>% apply(1, FUN=function(v) v[["isbns"]][["isbn10"]])
books$isbn13 <- books %>% select("isbns") %>% apply(1, FUN=function(v) v[["isbns"]][["isbn13"]])
books %<>%
unnest(isbn10, isbn13) %>% select(c("rank", "weeks_on_list", "author", "title", "amazon_product_url", "isbn10", "isbn13"))
datatable(books)