Learn R Programming

tidyjson (version 0.2.2)

gather_keys: Stack a JSON

Description

Given a JSON key value structure, like "key1": 1, "key2": 2, the gather_keys() function duplicates the rows of the tbl_json data.frame for every key, adds a new column (default name "key") to capture the key names, and then dives into the JSON values to enable further manipulation with downstream tidyjson functions.

Usage

gather_keys(x, column.name = "key")

Arguments

x
a tbl_json whose JSON attribute should always be an object
column.name
the name to give to the column of key names created

Value

a tbl_json with a new column (column.name) that captures the keys and JSON attribute of the associated value data

Details

This allows you to *enter into* the keys of the objects just like `gather_array` let you enter elements of the array.

Examples

Run this code
library(magrittr)  # for %>%
'{"name": "bob", "age": 32}' %>% gather_keys %>% json_types

Run the code above in your browser using DataLab