Fundamental Techniques - Import (R): jsonlite

Package:
jsonlite

Functionality:
Convert R objects to/from JSON

Description:
These functions are used to convert between JSON data and R objects. The toJSON and fromJSON functions use a class based mapping, which follows conventions outlined in this paper: https://arxiv.org/abs/1403.2805 (also available as vignette).

Demonstration:
The input data is a json file.
At the end of this demonstration, you will what options should be specified in order to import json data in R.

Function to test (default settings):
fromJSON(txt, simplifyVector = TRUE, simplifyDataFrame = simplifyVector, simplifyMatrix = simplifyVector, flatten = FALSE, ...)

Input file:
https://api.github.com/users/hadley/repos

###################
library(jsonlite) #
###################

# read json
json_data = fromJSON("https://api.github.com/users/hadley/repos", flatten = T)

head(json_data[,1:5])
##          id                          node_id                  name                      full_name private
## 1  40423928 MDEwOlJlcG9zaXRvcnk0MDQyMzkyOA== 15-state-of-the-union hadley/15-state-of-the-union   FALSE
## 2  40544418 MDEwOlJlcG9zaXRvcnk0MDU0NDQxOA==     15-student-papers     hadley/15-student-papers   FALSE
## 3 133108703 MDEwOlJlcG9zaXRvcnkxMzMxMDg3MDM=                 18-fp                 hadley/18-fp   FALSE
## 4  14984909 MDEwOlJlcG9zaXRvcnkxNDk4NDkwOQ==              500lines              hadley/500lines   FALSE
## 5  12241750 MDEwOlJlcG9zaXRvcnkxMjI0MTc1MA==                 adv-r                 hadley/adv-r   FALSE
## 6   5154874     MDEwOlJlcG9zaXRvcnk1MTU0ODc0               appdirs               hadley/appdirs   FALSE

Summary: jsonlite is a very user-friendly package for importing json file.

Comments