I am after a way (preferably an existing function) that can locate legitimate JSON data within a character string
What I know already
As shown here, jsonlite::fromJSON()
can parse JSON, like so:
library(jsonlite)
json_glob_1 <- "{ \"age\": 22}"
json_glob_2 <- "{ \"name\":\"John\" }"
fromJSON(json_glob_1)
# $age
# [1] 22
fromJSON(json_glob_2)
# $name
# [1] "John"
What I do not know
Is there a function that can accept an impure string and return the JSON glob(s) from within that string; e.g.
messy_string_with_json <- paste0("lsdfjksdlfjk dkfjsldfkjs fkjsdf",
json_glob_1,
"slkdfjlskdfj sfkdjflskdjf sdfk",
json_glob_2,
"32345jlskdfj")
find_JSON(messy_string_with_json)
[[1]]
[1] "{ \"age\": 22}"
[2] "{ \"name\":\"John\" }"