Learn R Programming

tidyjson (version 0.3.2)

is_json: Predicates to test for specific JSON types in tbl_json objects

Description

These functions are often useful with filter to filter complex JSON by type before applying gather_object or gather_array.

Usage

is_json_string(.x)

is_json_number(.x)

is_json_logical(.x)

is_json_null(.x)

is_json_array(.x)

is_json_object(.x)

is_json_scalar(.x)

Value

a logical vector

Arguments

.x

a json string or tbl_json object

See Also

json_types for creating a new column to identify the type of every JSON document

Examples

Run this code

# Test a simple example
json <- '[1, "string", true, [1, 2], {"name": "value"}, null]' %>% gather_array
json %>% is_json_number
json %>% is_json_array
json %>% is_json_scalar

# Use with filter
library(dplyr)
json %>% filter(is_json_object(.))

# Combine with filter in advance of using gather_array
companies[1:5] %>% gather_object %>% filter(is_json_array(.))
companies[1:5] %>% gather_object %>% filter(is_json_array(.)) %>%
  gather_array

# Combine with filter in advance of using gather_object
companies[1:5] %>% gather_object %>% filter(is_json_object(.))
companies[1:5] %>% gather_object %>% filter(is_json_object(.)) %>%
  gather_object("name2")

Run the code above in your browser using DataLab