View source: R/json_complexity.R
json_complexity | R Documentation |
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.
json_complexity(.x, column.name = "complexity")
.x |
a json string or tbl_json object |
column.name |
the name to specify for the length column |
a tbl_json
object
json_lengths
to compute the length of each value
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.