I am trying to work with a nested JSON format similar to that below. What I ultimately need is for the data frame to have only two rows of data, one for John and one for Sam, with the other data in a format like below. So this particular data frame would have 2 rows and 7 columns.
Name RD1 RD2 Hours1 Hours2 Billable1 Billable2
John
Sam
How could this be accomplished? Thank you in advance!
Here's the code:
library(jsonlite)
options(stringsAsFactors = FALSE)
rawData <- "document.txt"
processedData <- fromJSON(rawData, flatten = TRUE)
processedData <- processedData[, c("name", "records")]
unnestedJSON <- unnest(processedData, records)
document.txt contains this information:
[
{
"name": "John",
"records": [
{
"reportDate": "2018-07-20",
"hours": 204,
"billable": 32844
},
{
"reportDate": "2018-03-25",
"hours": 234,
"billable": 37715
}
]
},
{
"name": "Sam",
"records": [
{
"reportDate": "2018-06-18",
"hours": 187,
"billable": 13883
},
{
"reportDate": "2018-04-02",
"hours": 176,
"billable": 13467
}
]
}
]