# Stringify some data
jsoncars <- toJSON(mtcars, pretty=TRUE)
cat(jsoncars)
# Parse it back
fromJSON(jsoncars)
# Parse escaped unicode
fromJSON('{"city" : "Z\\u00FCrich"}')
# Decimal vs significant digits
toJSON(pi, digits=3)
toJSON(pi, digits=I(3))
if (FALSE) {
#retrieve data frame
data1 <- fromJSON("https://api.github.com/users/hadley/orgs")
names(data1)
data1$login
# Nested data frames:
data2 <- fromJSON("https://api.github.com/users/hadley/repos")
names(data2)
names(data2$owner)
data2$owner$login
# Flatten the data into a regular non-nested dataframe
names(flatten(data2))
# Flatten directly (more efficient):
data3 <- fromJSON("https://api.github.com/users/hadley/repos", flatten = TRUE)
identical(data3, flatten(data2))
}
Run the code above in your browser using DataLab