View source: R/ensure_json_stat2.R
| ensure_json_stat2 | R Documentation |
Ensures that a PxWebApi v2 URL requests data in JSON-stat2 format by enforcing
outputFormat=json-stat2.
ensure_json_stat2(url)
url |
A character string of length one giving a PxWebApi v2 data URL. |
The function behaves as follows:
If the URL already contains outputFormat=json-stat2, it is
returned unchanged.
If the URL contains an outputFormat parameter with another
value (e.g. csv), only the value is replaced by
json-stat2, leaving the rest of the URL unchanged.
If the URL does not contain any outputFormat parameter,
outputFormat=json-stat2 is appended.
Matching of parameter names and values is case-insensitive, but the resulting
URL always uses the canonical camelCase form
outputFormat=json-stat2.
This function is intended for internal use to guarantee a consistent and standardized output format across different PxWebApi v2 providers.
A character string with outputFormat=json-stat2 enforced.
This function is written and documented with help from ChatGPT.
url1 <- "https://api.no/data?lang=en"
url1
ensure_json_stat2(url1)
url2 <- paste0(url1, "&valueCodes[Tid]=top(2)")
url2
ensure_json_stat2(url2)
url3 <- paste0(url1, "&outputFormat=csv&valueCodes[Tid]=?")
url3
ensure_json_stat2(url3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.