Skip to content

Instantly share code, notes, and snippets.

@giocomai
Last active October 1, 2018 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giocomai/fce7069190fe1933c61fdabf5a5711f5 to your computer and use it in GitHub Desktop.
Save giocomai/fce7069190fe1933c61fdabf5a5711f5 to your computer and use it in GitHub Desktop.
Convert to csv json from FactChecks and Data Commons.org
if (!require("pacman")) install.packages("pacman")
pacman::p_load("jsonlite")
pacman::p_load("tidyverse")
#https://www.datacommons.org/docs/download.html
text <- readLines(con = "fact_checks_20180502.txt")
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed('<script type=\"application/ld+json\">'))
text <- stringr::str_remove_all(string = text, pattern = stringr::fixed("</script>"))
txtList <- purrr::map(.x = text, .f = fromJSON, simplifyDataFrame = TRUE, flatten = TRUE)
df <- purrr::map_df(.x = txtList, .f = as.data.frame)
write_csv(x = df, path = "fact_checks_20180502.csv")
# could perhaps be accomplished more tidily with jsonld
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment