Given the JSON structure contains nested key:value and key:arrays, you can't get a simple data.frame
directly with your JSON data. You need to access the specific components and convert those to a data.frame
For example, in the data you've provided we now that url
is a list
str(url)
# List of 2
# ...
# the two elements being
names(url)
# [1] "title" "variables"
So we can access these elements
str(url$title)
# chr "Felte småvilt, etter region, småvilt og intervall (år)"
str(url$variables)
# 'data.frame': 4 obs. of 6 variables:
# $ code : chr "Region" "Smaviltjakt" "ContentsCode" "Tid"
# $ text : chr "region" "småvilt" "statistikkvariabel" "intervall (år)"
# $ values :List of 4
# ..$ : chr "0" "01" "02" "03" ...
# ..$ : chr "00" "01" "02" "03" ...
# ..$ : chr "Smaavilt"
# ..$ : chr "1991-1992" "1992-1993" "1993-1994" "1994-1995" ...
You now have to work out what specific data components you want.
Borrowing from @antoine-sac 's comment, we can create a list of four data.frames
:
df_list = list();
for(i in 1:4) {
df_list[[url$variables$code[i]]] <- data.frame(val=url$variables$values[[i]],
description=url$variables$valueTexts[[i]])
}
Finally; you should get familar working with lists, not just data.frames. They are important in R.