I have a JSON string called test
in which some elements contain more than one key (for example, foo and bar).
My goal is to only extract the values of foo
. How can one do this with R?
I have tried converting to both matrix and data.frame but this does not help solve the issue.
> test
[1] "{\"foo\":[1,2,3],\"bar\":[0]}" "{\"foo\":[1]}" "{\"foo\":[4], \"bar\":[1]}"
[4] "{\"foo\":[2]}" "{\"foo\":[1,2]}" "{\"foo\":[3]}"
Any help would be appreciated
dput(test)
c("{\"foo\":[1,2,3],\"bar\":[0]}", "{\"foo\":[1]}", "{\"foo\":[4], \"bar\":[1]}",
"{\"foo\":[2]}", "{\"foo\":[1,2]}", "{\"foo\":[3]}")