is_json: Predicates to test for specific JSON types in 'tbl_json'...

is_jsonR Documentation

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)

Arguments

.x

a json string or tbl_json object

Value

a logical vector

See Also

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

Examples


# 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")

tidyjson documentation built on Jan. 7, 2023, 1:14 a.m.