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

Description Usage Arguments Value See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 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")

jeremystan/tidyjson documentation built on May 17, 2017, 6:14 p.m.