2025-12-15
{"array": [ "object1":
{"name1": "property-string/bool",
"name2": number},
"object2": {"name222": "property..."}
]
}
https://www.fbi.gov/wanted/api
https://api.fbi.gov/docs#/wanted/_wanted__wanted_get
the basic api url: https://api.fbi.gov/wanted/v1/list
Concatenate parameters:
first param: use ?param=value
2nd+ param: use ¶m=value
https://api.fbi.gov/wanted/v1/list?race=black&sex=female&poster_classification=missing
Diacritics, punctuation, spaces!!!
reserved characters TRUE, too
[1] "B%C3%A4rbel%20M%C3%BCller%3F%21"
https://api.fbi.gov/wanted/v1/list?field_offices=seattle
items listhttr::GET in Rtext <- httr::GET("https://api.fbi.gov/wanted/v1/list?page=1") %>%
httr::content(as = "text")
text %>% stringr::str_trunc(width = 350, ellipsis = ".....")[1] "{\"total\":1060,\"items\":[{\"possible_states\":null,\"warning_message\":null,\"field_offices\":[\"lasvegas\"],\"details\":\"<p>The Federal Bureau of Investigation's Las Vegas Field Office in Nevada is seeking the public's assistance in identifying the unknown suspect responsible for the defacement of Federal Buildings located at 501 South Las Vegas Boulevar....."
jsonlite::fromJSONitemsitemsitems [1] "possible_states" "warning_message" "field_offices"
[4] "details" "locations" "age_range"
[7] "path" "occupations" "eyes_raw"
[10] "scars_and_marks" "weight" "poster_classification"
[13] "possible_countries" "eyes" "files"
[16] "modified" "age_min" "caution"
[19] "description" "person_classification" "hair"
[22] "reward_max" "title" "coordinates"
[25] "place_of_birth" "languages" "race_raw"
[28] "reward_min" "complexion" "aliases"
[31] "url" "ncic" "height_min"
[34] "race" "publication" "weight_max"
[37] "subjects" "images" "suspects"
[40] "remarks" "reward_text" "nationality"
[43] "legat_names" "dates_of_birth_used" "status"
[46] "build" "weight_min" "hair_raw"
[49] "uid" "sex" "height_max"
[52] "additional_information" "age_max" "pathId"
items as a data frameparse the JSON with jsonlite
make structure as flat as possible (almost default)
items as a data frame[1] "data.frame"
[1] "possible_states" "warning_message" "field_offices"
[4] "details" "locations" "age_range"
[7] "path" "occupations" "eyes_raw"
[10] "scars_and_marks" "weight" "poster_classification"
[13] "possible_countries" "eyes" "files"
[16] "modified" "age_min" "caution"
[19] "description" "person_classification" "hair"
[22] "reward_max" "title" "coordinates"
[25] "place_of_birth" "languages" "race_raw"
[28] "reward_min" "complexion" "aliases"
[31] "url" "ncic" "height_min"
[34] "race" "publication" "weight_max"
[37] "subjects" "images" "suspects"
[40] "remarks" "reward_text" "nationality"
[43] "legat_names" "dates_of_birth_used" "status"
[46] "build" "weight_min" "hair_raw"
[49] "uid" "sex" "height_max"
[52] "additional_information" "age_max" "pathId"
items_dfpurrr to avoid loopsRows: 20
Columns: 9
$ field_offices <list> "lasvegas", "louisville", <NULL>, "miami", "dalla…
$ occupations <list> <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <…
$ files <list> [<data.frame[1 x 2]>], [<data.frame[1 x 2]>], [<d…
$ coordinates <list> [], [], [], [], [], [], [], [], [], [], [], [], […
$ languages <list> <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <"English…
$ aliases <list> <NULL>, <NULL>, <NULL>, <NULL>, <"Cecilia Rodrigu…
$ subjects <list> "Seeking Information", "Criminal Enterprise Inves…
$ images <list> [<data.frame[5 x 4]>], [<data.frame[2 x 4]>], [<d…
$ dates_of_birth_used <list> <NULL>, "September 25, 1980", <NULL>, "March 27, …
(langs_df <- items_df %>%
select(title, languages, files, field_offices,
dates_of_birth_used) %>%
filter(map_lgl(languages, ~!is.null(.x))) ) %>%
glimpse()Rows: 2
Columns: 5
$ title <chr> "ELLA MAE BEGAY", "MIGUEL ANGEL AGUILAR OJEDA"
$ languages <list> <"English", "Navajo">, <"Spanish", "English">
$ files <list> [<data.frame[3 x 2]>], [<data.frame[2 x 2]>]
$ field_offices <list> <"albuquerque", "phoenix">, "philadelphia"
$ dates_of_birth_used <list> "September 28, 1958", "August 5, 1990"
tidyr::unnestunnest,
unnest_longer,
unnest_wider
tidyr::unnest_longerRows: 4
Columns: 5
$ title <chr> "ELLA MAE BEGAY", "ELLA MAE BEGAY", "MIGUEL ANGEL …
$ languages <chr> "English", "Navajo", "Spanish", "English"
$ files <list> [<data.frame[3 x 2]>], [<data.frame[3 x 2]>], [<da…
$ field_offices <list> <"albuquerque", "phoenix">, <"albuquerque", "phoe…
$ dates_of_birth_used <list> "September 28, 1958", "September 28, 1958", "Augu…
tidyr::unnest_widerRows: 2
Columns: 6
$ title <chr> "ELLA MAE BEGAY", "MIGUEL ANGEL AGUILAR OJEDA"
$ `languages--1` <chr> "English", "Spanish"
$ `languages--2` <chr> "Navajo", "English"
$ files <list> [<data.frame[3 x 2]>], [<data.frame[2 x 2]>]
$ field_offices <list> <"albuquerque", "phoenix">, "philadelphia"
$ dates_of_birth_used <list> "September 28, 1958", "August 5, 1990"
unnest_longer several columnsRows: 4
Columns: 5
$ title <chr> "ELLA MAE BEGAY", "ELLA MAE BEGAY", "MIGUEL ANGEL …
$ languages <chr> "English", "Navajo", "Spanish", "English"
$ files <list> [<data.frame[3 x 2]>], [<data.frame[3 x 2]>], [<da…
$ field_offices <chr> "albuquerque", "phoenix", "philadelphia", "philad…
$ dates_of_birth_used <list> "September 28, 1958", "September 28, 1958", "Augus…
unnest_longer column by column# A tibble: 6 × 5
title languages files field_offices dates_of_birth_used
<chr> <chr> <list> <chr> <list>
1 ELLA MAE BEGAY English <df> albuquerque <chr [1]>
2 ELLA MAE BEGAY Navajo <df> albuquerque <chr [1]>
3 ELLA MAE BEGAY English <df> phoenix <chr [1]>
4 ELLA MAE BEGAY Navajo <df> phoenix <chr [1]>
5 MIGUEL ANGEL AGUILAR OJEDA Spanish <df> philadelphia <chr [1]>
6 MIGUEL ANGEL AGUILAR OJEDA English <df> philadelphia <chr [1]>
Rows: 5
Columns: 3
$ title <chr> "ELLA MAE BEGAY", "ELLA MAE BEGAY", "ELLA MAE BEGAY", "MIGUEL AN…
$ url <chr> "https://www.fbi.gov/wanted/kidnap/ella-mae-begay/download.pdf",…
$ name <chr> "English", "DIN BIZAAD KEHGO", "EN ESPAOL", "English", "EN ESPAO…
unnest_wider(un05_df <- langs_df %>%
select(title, files) %>%
unnest_wider(files, names_sep = "---")) %>%
glimpse()Rows: 2
Columns: 3
$ title <chr> "ELLA MAE BEGAY", "MIGUEL ANGEL AGUILAR OJEDA"
$ `files---url` <list<chr>> <"https://www.fbi.gov/wanted/kidnap/ella-mae-begay/down…
$ `files---name` <list<chr>> <"English", "DIN BIZAAD KEHGO", "EN ESPAOL">, <"E…
[[1]]
[[1]]$url
[1] "https://www.fbi.gov/wanted/kidnap/ella-mae-begay/download.pdf"
[2] "https://www.fbi.gov/wanted/kidnap/ella-mae-begay/ella-mae-begay_navajo.pdf/@@download/file/ella-mae-begay_Navajo.pdf"
[3] "https://www.fbi.gov/wanted/kidnap/ella-mae-begay/begayspanish.pdf/@@download/file/BegaySpanish.pdf"
[[1]]$name
[1] "English" "DIN BIZAAD KEHGO" "EN ESPAOL"
[[2]]
[[2]]$url
[1] "https://www.fbi.gov/wanted/murders/miguel-angel-aguilar-ojeda/download.pdf"
[2] "https://www.fbi.gov/wanted/murders/miguel-angel-aguilar-ojeda/ojedaspanish2.pdf/@@download/file/OjedaSpanish2.pdf"
[[2]]$name
[1] "English" "EN ESPAOL"
hoist nested list elements into columns title languages
1 ELLA MAE BEGAY English, Navajo
2 MIGUEL ANGEL AGUILAR OJEDA Spanish, English
POSTER_URL
1 https://www.fbi.gov/wanted/kidnap/ella-mae-begay/download.pdf, https://www.fbi.gov/wanted/kidnap/ella-mae-begay/ella-mae-begay_navajo.pdf/@@download/file/ella-mae-begay_Navajo.pdf, https://www.fbi.gov/wanted/kidnap/ella-mae-begay/begayspanish.pdf/@@download/file/BegaySpanish.pdf
2 https://www.fbi.gov/wanted/murders/miguel-angel-aguilar-ojeda/download.pdf, https://www.fbi.gov/wanted/murders/miguel-angel-aguilar-ojeda/ojedaspanish2.pdf/@@download/file/OjedaSpanish2.pdf
POSTER_NAMES field_offices dates_of_birth_used
1 English, DIN BIZAAD KEHGO, EN ESPAOL albuquerque, phoenix September 28, 1958
2 English, EN ESPAOL philadelphia August 5, 1990
hoist, then unnest.langs_FilesAsList %>%
tidyr::hoist(files, POSTER_URL = list( 1L), POSTER_NAMES = list(2L)) %>%
unnest_longer(c(starts_with("POSTER")))# A tibble: 5 × 6
title languages POSTER_URL POSTER_NAMES field_offices dates_of_birth_used
<chr> <list> <chr> <chr> <list> <list>
1 ELLA MAE … <chr [2]> https://w… English <chr [2]> <chr [1]>
2 ELLA MAE … <chr [2]> https://w… DIN BIZAAD … <chr [2]> <chr [1]>
3 ELLA MAE … <chr [2]> https://w… EN ESPAOL <chr [2]> <chr [1]>
4 MIGUEL AN… <chr [2]> https://w… English <chr [1]> <chr [1]>
5 MIGUEL AN… <chr [2]> https://w… EN ESPAOL <chr [1]> <chr [1]>
operations on lists in general: purrr
purrr::map(<your list>, ~ <some function on your list>(.x, <other arguments>))
test_df <- langs_df
for (i in 1:nrow(langs_df)) {
test_df$files[[i]] <- as.list(test_df$files[[i]])
}
test_df$files[[1]]$url
[1] "https://www.fbi.gov/wanted/kidnap/ella-mae-begay/download.pdf"
[2] "https://www.fbi.gov/wanted/kidnap/ella-mae-begay/ella-mae-begay_navajo.pdf/@@download/file/ella-mae-begay_Navajo.pdf"
[3] "https://www.fbi.gov/wanted/kidnap/ella-mae-begay/begayspanish.pdf/@@download/file/BegaySpanish.pdf"
$name
[1] "English" "DIN BIZAAD KEHGO" "EN ESPAOL"