library(jsonlite)
  1. What is the title of book10?
  2. How many pages in book10?
  3. How many characters in book 10?
book10 <- fromJSON("http://anapioficeandfire.com/api/books/10")

book10$name    # title
[1] "The Rogue Prince"
The Rogue Prince
book10$numberOfPages  # pages in book 10
[1] 832
length(book10$characters)  # Number of characters in book 10
[1] 55

Bonus Round

  1. How many different publishers are there?
  2. How many books did each publisher publish?
library(tidyverse)  # because I like working with modern data frames and tidy data
Loading tidyverse: ggplot2
Loading tidyverse: tibble
Loading tidyverse: tidyr
Loading tidyverse: readr
Loading tidyverse: purrr
Loading tidyverse: dplyr
Conflicts with tidy packages ----------------------------------------------
filter(): dplyr, stats
lag():    dplyr, stats
allBooks <- fromJSON("http://anapioficeandfire.com/api/books")

allBooks %>% 
  tbl_df() %>%                                            # convert to tibble
  group_by(publisher) %>%
  summarise(TitlesPublished = length(publisher))

  1. List each book with its publisher?
paste(allBooks$name, allBooks$publisher,sep = " --- ")            # List each book with its publisher
 [1] "A Game of Thrones --- Bantam Books"            
 [2] "A Clash of Kings --- Bantam Books"             
 [3] "A Storm of Swords --- Bantam Books"            
 [4] "The Hedge Knight --- Dabel Brothers Publishing"
 [5] "A Feast for Crows --- Bantam Books"            
 [6] "The Sworn Sword --- Marvel"                    
 [7] "The Mystery Knight --- Tor Fantasy"            
 [8] "A Dance with Dragons --- Bantam Books"         
 [9] "The Princess and the Queen --- Tor Books"      
[10] "The Rogue Prince --- Bantam Books"             
A Game of Thrones --- Bantam Books

A Clash of Kings --- Bantam Books

A Storm of Swords --- Bantam Books

The Hedge Knight --- Dabel Brothers Publishing

A Feast for Crows --- Bantam Books

The Sworn Sword --- Marvel

The Mystery Knight --- Tor Fantasy

A Dance with Dragons --- Bantam Books

The Princess and the Queen --- Tor Books

The Rogue Prince --- Bantam Books

  1. What is the total number of pages of all books in the series?
sum(allBooks$numberOfPages)                                       # Total number of pages of all books
[1] 6626
LS0tDQp0aXRsZTogIlVzaW5nIFIgdG8gT3JjaGVzdHJhdGUgQVBJcyAtLS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