APIs & JSON

Intermediate Importing Data in R

Filip Schouwenaars

Instructor, DataCamp

Other data formats

  • Before: pages and files from the web

  • JSON

  • Simple, concise, well-structured

  • Human-readable

  • Easy to parse and generate for computers

  • For communication with Web APIs

Intermediate Importing Data in R

API

  • Application Programming Interface

  • Set of routines and protocols for building software

  • How different components interact

  • Web API

    • interface to get or add data to server

    • HTTP verbs (GET and others)

Intermediate Importing Data in R

Twitter

Intermediate Importing Data in R

Info on Rain Man (1988)

url <- "http://www.imdb.com/title/tt0095953/"
download.file(url, "local_imdb.html")

ch_4_1_slides.023.png

Intermediate Importing Data in R

Rain Man JSON (OMDb API)

Intermediate Importing Data in R

jsonlite

  • Jeroen Ooms

  • Improvement of earlier packages

  • Consistent, robust

  • Support all use-cases

Intermediate Importing Data in R

Rain Man list in R

install.packages("jsonlite")
library(jsonlite)

fromJSON("http://www.omdbapi.com/?i=tt0095953&r=json")
List of 20
 $ Title     : chr "Rain Man"
 $ Year      : chr "1988"
 $ Rated     : chr "R"
 $ Released  : chr "16 Dec 1988"
 $ Runtime   : chr "133 min"
 ...
 $ imdbVotes : chr "359,903"
 $ imdbID    : chr "tt0095953"
 $ Type      : chr "movie"
 $ Response  : chr "True"
  • Way more structure!
Intermediate Importing Data in R

Let's practice!

Intermediate Importing Data in R

Preparing Video For Download...