| Title: | Handle 'JSON-stat' Format in R |
|---|---|
| Description: | Handle 'JSON-stat' format (<https://json-stat.org>) in R. Not all features are supported, especially the extensive metadata features of 'JSON-stat'. |
| Authors: | Aaron Schumacher, Håkon Malmedal, Måns Magnusson |
| Maintainer: | Aaron Schumacher <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.3 |
| Built: | 2026-05-08 07:09:33 UTC |
| Source: | https://github.com/ajschumacher/rjstat |
Convert to jsonlite json object
as.json(x, ...)as.json(x, ...)
x |
an object to coerce to a json object. |
... |
additional arguments to be passed to or from methods. |
Currently only methods for jsonstat objects are implemented.
Create a JSON-stat object
as.jsonstat(x) is.jsonstat(x) is.jsonstat_dataset(x) is.jsonstat_collection(x) is.jsonstat_dimension(x)as.jsonstat(x) is.jsonstat(x) is.jsonstat_dataset(x) is.jsonstat_collection(x) is.jsonstat_dimension(x)
x |
a JSON-stat string, URL or file |
a JSON-stat object with subclass dataset, dimension or collection
file_path <- system.file("extdata", "oecd.json", package = "rjstat") x <- as.jsonstat(file_path) print(x) is.jsonstat(x) is.jsonstat_dataset(x) is.jsonstat_dimension(x)file_path <- system.file("extdata", "oecd.json", package = "rjstat") x <- as.jsonstat(file_path) print(x) is.jsonstat(x) is.jsonstat_dataset(x) is.jsonstat_dimension(x)
This function takes a JSON-stat format response and returns a data frame or a
list of data frames, with columns for each dimension and one value
column.
fromJSONstat(x, naming = "label", use_factors = FALSE, silent = FALSE)fromJSONstat(x, naming = "label", use_factors = FALSE, silent = FALSE)
x |
JSON-stat format response, or path or URL to such a response |
naming |
whether to use (longer) |
use_factors |
whether dimension categories should be factors or character objects |
silent |
suppress warnings |
For responses with class dataset: A data frame. For responses
with class collection: An unnamed list of one or more lists or data
frames. For responses with class bundle: A named list of one or more
data frames.
## Not run: oecd.canada.url <- "https://json-stat.org/samples/oecd-canada.json" results <- fromJSONstat(oecd.canada.url) names(results) ## End(Not run)## Not run: oecd.canada.url <- "https://json-stat.org/samples/oecd-canada.json" results <- fromJSONstat(oecd.canada.url) names(results) ## End(Not run)
id accessors of jsonstat objectsAccess and change ids of jsonstat objects.
id(x) id(x) <- valueid(x) id(x) <- value
x |
a |
value |
a character vector of up to the same length as |
JSON-stat is a JSON format for data dissemination. The rjstat package converts data frames to and from this format. The extensive metadata features of JSON-stat are not supported.
status accessors of jsonstat objectsAccess and change statuss of jsonstat objects.
status(x) status(x) <- valuestatus(x) status(x) <- value
x |
a |
value |
a character vector of up to the same length as |
This function takes a data frame or list of data frames and returns
a string representation in JSON-stat format. The input data frame(s)
must be in maximally long tidy format: with only one value
column and all other columns representing dimensions.
toJSONstat(x, value = "value", ...)toJSONstat(x, value = "value", ...)
x |
a data frame or list of data frames |
value |
name of value column |
... |
arguments passed on to |
For a data frame: A JSON-stat format response with class
dataset. For a list of data frames: A JSON-stat format response with
class collection.
library(reshape) irises <- melt(cbind(iris, Specimen=rep(1:50, 3)), id.vars=c("Species", "Specimen")) irisJSONstat <- toJSONstat(list(iris=irises)) cat(substr(irisJSONstat, 1, 76)) # Add indentation whitespace toJSONstat(as.data.frame(Titanic), value = "Freq", pretty = TRUE)library(reshape) irises <- melt(cbind(iris, Specimen=rep(1:50, 3)), id.vars=c("Species", "Specimen")) irisJSONstat <- toJSONstat(list(iris=irises)) cat(substr(irisJSONstat, 1, 76)) # Add indentation whitespace toJSONstat(as.data.frame(Titanic), value = "Freq", pretty = TRUE)