I am building an api at the moment which has several layers of information. At the moment I am using tibbles and nesting the information under columns:
# A tibble: 1 x 3
APICallTimeGMT Error some_data
<dttm> <list> <list>
1 2018-10-19 11:43:10 <data.frame [1 × 2]> <tibble [2 × 3]>
When I then turn this into JSON
using jsonlite::toJSON
, I get a lot list []
brackets. Is there a way to turn these specific objects into a json object instead of a list. So, what class (instead of data.frame) should the nested object be?
Current output:
Desired Output:
Here is the dput(x)
for reproducibility:
structure(list(APICallTimeGMT = structure(1539949390.26164, class = c("POSIXct",
"POSIXt")), Error = list(structure(list(msg = structure(1L, .Label = "OK", class = "factor"),
status = 200), .Names = c("msg", "status"), row.names = c(NA,
-1L), class = "data.frame")), some_data = list(structure(list(
Outcome = c("Case1", "Case2"), predictions = list(structure(list(
ClassA = 0.4, ClassB = 0.1, ClassC = 0.5), .Names = c("ClassA",
"ClassB", "ClassC"), row.names = c(NA, -1L), class = "data.frame"),
structure(list(ClassA = 0.4, ClassB = 0.1, ClassC = 0.5), .Names = c("ClassA",
"ClassB", "ClassC"), row.names = c(NA, -1L), class = "data.frame")),
meta = list(structure(list(model = structure(1L, .Label = "Awesome AI", class = "factor"),
runs = 55), .Names = c("model", "runs"), row.names = c(NA,
-1L), class = "data.frame"), structure(list(model = structure(1L, .Label = "Awesome AI", class = "factor"),
runs = 55), .Names = c("model", "runs"), row.names = c(NA,
-1L), class = "data.frame"))), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"), .Names = c("Outcome", "predictions", "meta"
)))), row.names = c(NA, -1L), .Names = c("APICallTimeGMT", "Error",
"some_data"), class = c("tbl_df", "tbl", "data.frame"))