tidyjson (version 0.2.2)

json_lengths: Add a column that contains the length of the JSON data

Description

When investigating JSON data it can be helpful to identify the lengths of the JSON objects or arrays, especialy when they are 'ragged' across documents. The json_lengths() function adds a column (default name "length") that contains the 'length' of the JSON associated with each row. For objects, this will be equal to the number of keys. For arrays, this will be equal to the length of the array. All scalar values will be of length 1.

Usage

json_lengths(x, column.name = "length")

Arguments

x
a tbl_json object
column.name
the name to specify for the length column

Value

a tbl_json object with column.name column that tells the length

Examples

Run this code
library(magrittr)  # for %>%
c('[1, 2, 3]', '{"k1": 1, "k2": 2}', '1', {}) %>% json_lengths

Run the code above in your browser using DataLab