Reputation: 71
library(jsonlite)
test <-as.dataframe(fromJSON('http://api.worldbank.org/v2/countries/all/indicators/SH.STA.ACSN?format=json')[2])
names(test)
However, it looks like there are more columns, such as the "country" column actually has "country.value" and "country.id" columns. This is annoying because "country.value" does not seem to exist, thus the following code returns errors saying this column is not in the data frame test. I only want to keep country.value. How can I resolve this? Does it have anything to do with how JSON returns data in R?
test$country.value
Upvotes: 2
Views: 233
Reputation: 850
Does flatten work for you? I am not sure.
library(jsonlite)
test <-data.frame(fromJSON('http://api.worldbank.org/v2/countries/all/indicators/SH.STA.ACSN?format=json')[2])
names(test)
test_flatten<-flatten(test)
names(test_flatten)
Upvotes: 0