| json_structure {tidyjson} | R Documentation |
Recursively structures arbitrary JSON data into a single data frame
Description
Returns a tbl_json object where each row corresponds to a leaf
in the JSON structure. The first row corresponds to the JSON document as
a whole. If the document is a scalar value (JSON string, number, logical
or null), then there will only be 1 row. If instead it is an object or
an array, then subsequent rows will recursively correspond to the elements
(and their children) of the object or array.
Usage
json_structure(.x)
Arguments
.x |
a json string or tbl_json object |
Details
The columns in the tbl_json returend are defined as
-
document.id1L if.xis a single JSON string, otherwise the index of.x. -
parent.idthe string identifier of the parent node for this child. -
levelwhat level of the hierarchy this child resides at, starting at0Lfor the root and incrementing for each level of nested array or object. -
indexwhat index of the parent object / array this child resides at (fromgather_arrayfor arrays). -
child.ida unique ID for this leaf in this document, represented as <parent>.<index> where <parent> is the ID for the parent and <index> is this index. -
seqthe sequence of names / indices that led to this child (parents that are arrays are excluded) as a list, where character strings denote objects and integers denote array positions -
nameif this is the value of an object, what was the name that it is listed under (fromgather_object). -
typethe type of this object (fromjson_types). -
lengththe length of this object (fromjson_lengths).
Value
a tbl_json object
See Also
json_schema to create a schema for a JSON document or
collection
Examples
# A simple string
'"string"' %>% json_structure
# A simple object
'{"name": "value"}' %>% json_structure
# A complex array
'[{"a": 1}, [1, 2], "a", 1, true, null]' %>% json_structure
# A sample of structure rows from a company
library(dplyr)
companies[1] %>% json_structure %>% sample_n(5)