I've seen there are already plenty of questions regarding purrr, json and nested lists. They were all very helpful, but I am stuck with one issue which seemed pretty straightforward to me initally.
I have a list, called list_ref (originating from an API request) which has many elements and nested sublists.
I am able to extract the sublist I am interested in for 1 specific list, e.g. with
d <- list_ref[[1]][["Data"]][["Metadaten"]][["Judikatur"]]
What I need is to get the sublist 'Judikatur' for all elements. Not only the first one.
I am missing something obvious. Many thanks.
<!-- language-all: lang-r -->
library(httr)
library(tidyverse)
#> Warning: package 'tidyr' was built under R version 3.6.3
#> Warning: package 'forcats' was built under R version 3.6.3
library(jsonlite)
#> Warning: package 'jsonlite' was built under R version 3.6.2
#>
#> Attaching package: 'jsonlite'
#> The following object is masked from 'package:purrr':
#>
#> flatten
api_base_link <- "https://data.bka.gv.at/ris/api/v2.5/judikatur"
get_res <- GET(url=api_base_link, query=list(Suchworte="Hunger", #search terms
Applikation="Bvwg",
Norm="AsylG 2005",
DokumenteProSeite="OneHundred", #results per page
Seitennumer=1)) #page number; here only first page
content_res <- content(get_res, as="text")
content_res_json <- fromJSON(content_res, simplifyDataFrame = F)
list_ref <- content_res_json$OgdSearchResult$OgdDocumentResults$OgdDocumentReference
d <- list_ref[[1]][["Data"]][["Metadaten"]][["Judikatur"]]
list_ref %>%
purrr::flatten() %>%
map(., magrittr::extract, "Data", "metadaten", "Judikatur")
#> Error in .x[...]: incorrect number of dimensions
<sup>Created on 2020-04-10 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>