flattenj_one {mojson}R Documentation

Single JSON Object Flatten

Description

Transform a JSON object into a flattened data frame in a serialization way.

Usage

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

Arguments

dat

list. The list from a JSON object.

sep

character. A character/string used to separate keys in the nesting path. 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.

Details

The function flattens a single JSON object into a data frame with two different schemas according to the compact value.

It actually applies the serialization way for flattening, which means the early values correspondingly appear in the heading rows of the data frame. And if the value is a list object in the original data or a non-named list/vector in the R environment, the path will be correspondingly appended with an integer to specify each list element. For example, in the raw JSON file, "{'a':[1, 2, 3]}" will be data.frame(paths = c('a1', 'a2', 'a3'), values = c(1, 2, 3)). Great credits to the answer of Tommy.

Value

data frame. The flattened result.

See Also

expanddf.

Examples

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))))
flattenj_one(j)
flattenj_one(j, compact = FALSE)


[Package mojson version 0.1 Index]