json_complexity: Compute the complexity (recursively unlisted length) of JSON...

Description Usage Arguments Value See Also Examples

View source: R/json_complexity.R

Description

When investigating complex JSON data it can be helpful to identify the complexity of deeply nested documents. The json_complexity function adds a column (default name "complexity") that contains the 'complexity' of the JSON associated with each row. Essentially, every on-null scalar value is found in the object by recursively stripping away all objects or arrays, and the complexity is the count of these scalar values. Note that 'null' has complexity 0, as do empty objects and arrays.

Usage

1
json_complexity(.x, column.name = "complexity")

Arguments

.x

a json string or tbl_json object

column.name

the name to specify for the length column

Value

a tbl_json object

See Also

json_lengths to compute the length of each value

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# A simple example
json <- c('[1, 2, [3, 4]]', '{"k1": 1, "k2": [2, [3, 4]]}', '1', 'null')

# Complexity is larger than length for nested objects
json %>% json_lengths %>% json_complexity

# Worldbank has complexity ranging from 8 to 17
library(magrittr)
worldbank %>% json_complexity %$% table(complexity)

# Commits are much more regular
commits %>% gather_array %>% json_complexity %$% table(complexity)

jeremystan/tidyjson documentation built on May 19, 2019, 5:09 a.m.