Description Usage Arguments Details Value See Also Examples
View source: R/format_json_rowwise.R
Convert each row of a data frame to a JSON object (this basically produces ndjson).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | format_json_rowwise(
df,
null = c("list", "null"),
na = c("null", "string"),
auto_unbox = TRUE,
matrix = c("rowmajor", "columnmajor"),
Date = c("ISO8601", "epoch"),
POSIXt = c("string", "ISO8601", "epoch", "mongo"),
factor = c("string", "integer"),
complex = c("string", "list"),
raw = c("base64", "hex", "mongo"),
digits = 4,
json_verbatim = TRUE,
force = FALSE,
rownames = FALSE,
...
)
|
df |
A dataframe. |
null, na, POSIXt, factor, complex, matrix, Date |
passed on to |
auto_unbox, raw, digits, force, ... |
passed on to |
json_verbatim |
Leave JSON as it is and do not encode it again? |
rownames |
For data.frames add a field |
Under the hood jsonlite::stream_out
is used for the conversion.
A json2
vector of JSON objects.
1 2 3 4 5 6 7 8 9 10 11 12 13 | format_json_rowwise(mtcars[1:3, ])
# use a dataframe column for nested objects
df <- data.frame(x = 1:2)
df$y <- data.frame(z = c("a", "b"))
format_json_rowwise(df)
if (require("dplyr", quietly = TRUE, warn.conflicts = FALSE)) {
tibble <- tibble::tibble
# often useful in mutate/transmute
mtcars %>%
transmute(json = format_json_rowwise(tibble(mpg, cyl, extra = tibble(disp, hp))))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.