Learn R Programming

tidyjson (version 0.3.2)

json_types: Add a column that tells the 'type' of the JSON data

Description

The function json_types inspects the JSON associated with each row of the tbl_json object, and adds a new column ("type" by default) that identifies the type according to the JSON standard at http://json.org/.

Usage

json_types(.x, column.name = "type")

Value

a tbl_json object

Arguments

.x

a json string or tbl_json object

column.name

the name to specify for the type column

Details

This is particularly useful for inspecting your JSON data types, and can often follows after gather_array, gather_object or enter_object to inspect the types of the elements of JSON objects or arrays.

Examples

Run this code

# A simple example
c('{"a": 1}', '[1, 2]', '"a"', '1', 'true', 'null') %>% json_types

# Type distribution in the first 10 companies
library(dplyr)
companies[1:10] %>% gather_object %>% json_types %>% count(type)

Run the code above in your browser using DataLab