Unserialize data frame columns that contain JSON

unpack_json_cols(x, cols)

# S3 method for data.table
unpack_json_cols(x, cols)

# S3 method for data.frame
unpack_json_cols(x, cols)

Arguments

x

a data.frame

cols

character vector. The names of the text columns containing JSON strings that should be expanded.

Value

a data.frame with additional columns expanded from the columns containing JSON

Examples

x <- data.frame(
  name = "example data",
  fields = '{"letters":["a","b","c"], "LETTERS":["A","B","C"]}',
  stringsAsFactors = FALSE
)
res <- unpack_json_cols(x, "fields")
res
#>           name letters LETTERS
#> 1 example data a, b, c A, B, C
res$letters[[1]]
#> [1] "a" "b" "c"