json <- '{
"discards": {
"1000": "Record does not exist",
"1004": "Queue limit exceeded",
"1010": "Discarding timed-out partial msg"
},
"warnings": {
"0": "Phone number missing country code",
"1": "State code missing",
"2": "Zip code missing"
}
}'
## JSONpointer
j_flatten(json) |>
cat("\n")
## JSONpath
j_flatten(json, as = "R", path_type = "JSONpath") |>
str()
j_find_values(json, "Zip code missing", as = "tibble")
j_find_values(
json,
c("Queue limit exceeded", "Zip code missing"),
as = "tibble"
)
j_find_values_grep(json, "missing", as = "tibble")
## JSONpath
j_find_values_grep(json, "missing", as = "tibble", path_type = "JSONpath")
j_find_keys(json, "discards", as = "tibble")
j_find_keys(json, "1", as = "tibble")
j_find_keys(json, c("discards", "warnings"), as = "tibble")
## JSONpath
j_find_keys(json, "discards", as = "tibble", path_type = "JSONpath")
j_find_keys_grep(json, "discard", as = "tibble")
j_find_keys_grep(json, "1", as = "tibble")
j_find_keys_grep(json, "car.*/101", as = "tibble")
## JSONpath
j_find_keys_grep(json, "car.*\\['101", as = "tibble", path_type = "JSONpath")
## NDJSON
ndjson_file <-
system.file(package = "rjsoncons", "extdata", "example.ndjson")
j_flatten(ndjson_file) |>
noquote()
j_find_values_grep(ndjson_file, "e") |>
str()
Run the code above in your browser using DataLab