Learn R Programming

mojson (version 0.1)

flattenj: JSON Flatten

Description

Transform multiple JSON objects into a flattened data frame.

Usage

flattenj(dat, sep = "@", compact = TRUE)

Arguments

dat

list. Loaded result from a JSON file.

sep

character. A character/string passed to flattenj_one. Defaults to @ to avoid the occasional overriding. Not recommended to use some risky characters like . and \. When compact=FALSE, it is unnecessary to assign sep explicitly, unless @ has been used in the key fields.

compact

logical. Whether to generate the compact or completely expanded data frame. Defaults to TRUE.

Value

data frame. The flattened result.

Details

The function flattens multiple JSON objects into a new data frame. The result contains multiple columns. If compact=TRUE, it returns paths, values and index columns, otherwise level1, level2, ..., values and index. The index column stores the id of each JSON object.

See Also

flattenj_one.

Examples

Run this code
# NOT RUN {
library(mojson)
j <- list(a = list(x = 1, y = 2),
         b = c(3, 4, list(z = 5, s = 6, t = list(m = 7, n = 8))))
j_multi <- list(j, j, j)
flattenj(j_multi)
flattenj(j_multi, compact=FALSE)

# }

Run the code above in your browser using DataLab