Hi I am trying to read the public holidays rJson file from the GOV.UK JSON file and convert into a useuable data frame but not with much success. I've used the jsonlite package to read the data as per the following :-
library(jsonlite)
holiday_json <- fromJSON("https://www.gov.uk/bank-holidays.json")
this returns a series of lists which i need to convert into a dataframe. I've tried various different solutions and they either return an error saying the dimensions of the data would be incorrect if i use as.dataframe or the data returned is not in the correct format at all(using unlist).
I want a 3 column data frame that contains the region the holiday is for i.e England,Wales,Scotland and Northern Ireland as well as what type of holiday it is and the date.
The first thing I find helpful when tackling a problem like this, with nested lists, is to look at the
str
ucture of the list:So, to put it into words, you have three sublists, with two sublists for each of those. I assume you want to pull out the events for each locality, and turn it all into one big dataframe. You can do that many ways, but maybe the easiest is using
map_df()
:Conveniently,
map_df()
takes the division element, and turns it into a column in the output dataframe.Output: