I'm stuck with a pretty particular issue. I have a database with a JSON field:
# A tibble: 1 x 3
field1 field2 JSONfield
<int> <chr> <chr>
1 43 stringgg "{\"typ\": \"Liste mit Punkten\", \"min~
Now, if I applied the following pattern:
dbGetQuery(pool, mydatabase) %>%
mutate(json = map(JSONfield, ~ fromJSON(.) %>%
as.data.frame(stringsAsFactors = FALSE))) %>%
unnest(json)
I would receive:
# A tibble: 2 x 10
field1 field2 JSONfield typ min max items.1 items.2 items.3
<int> <chr> <chr> <chr> <int> <int> <fct> <fct> <fct>
1 43 stringgg "{\"typ\": \"Liste mit~ List~ 0 1 first second third
2 43 stringgg "{\"typ\": \"Liste mit~ List~ 0 1 3 0 7
Though the Output I desire is:
# A tibble: 2 x 10
field1 field2 JSONfield typ min max items
<int> <chr> <chr> <chr> <int> <int> <list>
1 43 stringgg "{\"typ\": \"Liste mit~ List~ 0 1 <data.frame~
The JSON object looks like this:
{"typ": "Liste mit Punkten",
"min": 0,
"max": 1,
"items": [["first", "second", "third"],
[3, 0, 7]]}
Also the JSON objects that I have to deal with have a subset of up to 7 name/value pairs that may or may not occur in an object, therefore I'm looking for a rather unspecific solution.
I'm greatful for any help on this issue.
data.frameordata.tablein R cannot accept anotherdata.frame,data.tableas colume. Either you save then as nested list, or concatenate items into one string column.