R/parse_js1.R

Defines functions parse_js1

Documented in parse_js1

#' Get data ids from java script source
#'
#' @param script character, java script source code with data ids
#'
#' @return json in form of list with data ids
#'
parse_js1 <- function(script) {
  script_indexed <- script[seq(grep("filters: \\{", script) + 1, grep("left_columns: \\[", script) - 2)]

  gsub("\\b(?=([^']*'[^']*')*[^']*$)", "'", script_indexed, perl = TRUE) %>%
    gsub("'", "\"", x = .) %>%
    paste(collapse = "\n") %>%
    paste0("{", ... = ., "}") %>%
    jsonlite::fromJSON(simplifyVector = FALSE)
}

Try the fedstatAPIr package in your browser

Any scripts or data that you put into this service are public.

fedstatAPIr documentation built on March 31, 2023, 9:16 p.m.