├── .gitignore ├── .Rbuildignore ├── tests ├── testthat │ ├── notjsonstat.json │ ├── test-warnings.R │ ├── dataset2.json │ ├── dataset.json │ ├── test-datasets.R │ ├── test-classes.R │ ├── nonexistent.json │ ├── collection.json │ ├── test-jsonstat_accessors.R │ ├── test-constructor.R │ ├── test-input.R │ ├── test-values.R │ ├── order.json │ ├── collection_sample.json │ ├── bundle.json │ ├── test-output.R │ ├── test-factors.R │ ├── test-columns.R │ ├── canada.json │ ├── us-gsp.json │ ├── test-jsonstat_methods.R │ ├── hierarchy.json │ ├── oecd_tidy.json │ ├── oecd.json │ ├── oecd-canada-col.json │ └── galicia.json └── testthat.R ├── LICENSE ├── .travis.yml ├── man ├── validate_jsonstat.Rd ├── rjstat.Rd ├── id.Rd ├── as.json.Rd ├── status.Rd ├── as.jsonstat.Rd ├── fromJSONstat.Rd └── toJSONstat.Rd ├── rjstat.Rproj ├── DESCRIPTION ├── NAMESPACE ├── R ├── jsonstat.R ├── jsonstat_accessors.R ├── jsonstat_methods.R └── rjstat.R ├── README.md └── inst └── extdata └── oecd.json /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | .travis.yml 4 | -------------------------------------------------------------------------------- /tests/testthat/notjsonstat.json: -------------------------------------------------------------------------------- 1 | { 2 | "type_of_json": "Not json stat" 3 | } 4 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(rjstat) 3 | 4 | test_check("rjstat") 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2013, 2014, 2015, 2016, 2020, 2022, 2023 2 | COPYRIGHT HOLDER: Aaron Schumacher 3 | -------------------------------------------------------------------------------- /tests/testthat/test-warnings.R: -------------------------------------------------------------------------------- 1 | context("Warnings") 2 | 3 | test_that("warnings are suppressed", { 4 | expect_silent(fromJSONstat("nonexistent.json", silent = TRUE)) 5 | }) 6 | 7 | test_that("warnings work", { 8 | expect_warning(fromJSONstat("nonexistent.json"), "returning unparsed list", 9 | all = TRUE) 10 | }) 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | r: 3 | - release 4 | - devel 5 | sudo: required 6 | cache: packages 7 | 8 | # Be strict when checking our package 9 | warnings_are_errors: true 10 | 11 | r_github_packages: 12 | - jimhester/covr 13 | 14 | after_success: 15 | - Rscript -e 'covr::coveralls()' 16 | 17 | notifications: 18 | email: 19 | on_success: change 20 | on_failure: change 21 | -------------------------------------------------------------------------------- /tests/testthat/dataset2.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "class": "dataset", 4 | "label": "A dataset", 5 | "value": [1], 6 | "id": ["testdimension"], 7 | "size": [1], 8 | "dimension": { 9 | "testdimension": { 10 | "label": "A dimension", 11 | "category": { 12 | "index": ["testcategory"], 13 | "label": { 14 | "testcategory": "A category" 15 | } 16 | } 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /man/validate_jsonstat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jsonstat.R 3 | \name{validate_jsonstat} 4 | \alias{validate_jsonstat} 5 | \title{Function to validate json stat} 6 | \usage{ 7 | validate_jsonstat(x) 8 | } 9 | \description{ 10 | Now this is just a simple light-weight validation. 11 | Hopefully this can be complemented with a real json stat 12 | schema validator. 13 | } 14 | \keyword{internal} 15 | -------------------------------------------------------------------------------- /man/rjstat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rjstat.R 3 | \docType{package} 4 | \name{rjstat} 5 | \alias{rjstat} 6 | \alias{rjstat-package} 7 | \title{Read and write JSON-stat data sets} 8 | \description{ 9 | \href{https://json-stat.org}{JSON-stat} is a JSON format for data 10 | dissemination. The \pkg{rjstat} package converts data frames to and from this 11 | format. The extensive metadata features of JSON-stat are not supported. 12 | } 13 | -------------------------------------------------------------------------------- /rjstat.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Yes 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 4 10 | Encoding: UTF-8 11 | 12 | RnwWeave: knitr 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace,vignette 22 | -------------------------------------------------------------------------------- /man/id.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jsonstat_accessors.R 3 | \name{id} 4 | \alias{id} 5 | \alias{id<-} 6 | \title{\code{id} accessors of \code{jsonstat} objects} 7 | \usage{ 8 | id(x) 9 | 10 | id(x) <- value 11 | } 12 | \arguments{ 13 | \item{x}{a \code{jsonstat_dataset} object} 14 | 15 | \item{value}{a character vector of up to the same length as \code{id(x)}.} 16 | } 17 | \description{ 18 | Access and change \code{id}s of jsonstat objects. 19 | } 20 | -------------------------------------------------------------------------------- /tests/testthat/dataset.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "class": "dataset", 4 | "label": "A dataset", 5 | "value": [ 6 | 1 7 | ], 8 | "id": [ 9 | "testdimension" 10 | ], 11 | "size": [ 12 | 1 13 | ], 14 | "dimension": { 15 | "testdimension": { 16 | "label": "A dimension", 17 | "category": { 18 | "index": [ 19 | "testcategory" 20 | ], 21 | "label": { 22 | "testcategory": "A category" 23 | } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /man/as.json.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jsonstat_methods.R 3 | \name{as.json} 4 | \alias{as.json} 5 | \title{Convert to jsonlite json object} 6 | \usage{ 7 | as.json(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{an object to coerce to a json object.} 11 | 12 | \item{...}{additional arguments to be passed to or from methods.} 13 | } 14 | \description{ 15 | Convert to jsonlite json object 16 | } 17 | \details{ 18 | Currently only methods for \code{jsonstat} objects are implemented. 19 | } 20 | -------------------------------------------------------------------------------- /man/status.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jsonstat_accessors.R 3 | \name{status} 4 | \alias{status} 5 | \alias{status<-} 6 | \title{\code{status} accessors of \code{jsonstat} objects} 7 | \usage{ 8 | status(x) 9 | 10 | status(x) <- value 11 | } 12 | \arguments{ 13 | \item{x}{a \code{jsonstat_dataset} object} 14 | 15 | \item{value}{a character vector of up to the same length as \code{as.vector(x)} or a named list with index as vector names.} 16 | } 17 | \description{ 18 | Access and change \code{status}s of jsonstat objects. 19 | } 20 | -------------------------------------------------------------------------------- /tests/testthat/test-datasets.R: -------------------------------------------------------------------------------- 1 | context("Datasets") 2 | 3 | test_that("dataset names are correct", { 4 | fromJSONstat("bundle.json", naming = "label") %>% 5 | expect_named(c("A dataset with array value", 6 | "A dataset with object value")) 7 | fromJSONstat("bundle.json", naming = "id") %>% 8 | expect_named(c("dataset", "dataset2")) 9 | }) 10 | 11 | test_that("dataset names are correct for missing labels", { 12 | readLines("bundle.json")[-3] %>% 13 | fromJSONstat(naming = "label") %>% 14 | expect_named(c("dataset", "A dataset with object value")) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-classes.R: -------------------------------------------------------------------------------- 1 | context("Classes") 2 | 3 | test_that("dataset responses work", { 4 | fromJSONstat("dataset.json") %>% 5 | expect_s3_class("data.frame") %>% 6 | expect_named(c("A dimension", "value")) %>% 7 | getElement("value") %>% 8 | expect_equal(1) 9 | }) 10 | 11 | test_that("collection responses work", { 12 | fromJSONstat("collection.json") %>% 13 | expect_type("list") %>% 14 | getElement(1) %>% 15 | expect_s3_class("data.frame") %>% 16 | expect_named(c("A dimension", "value")) %>% 17 | getElement("value") %>% 18 | expect_equal(1) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/nonexistent.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "class": "collection", 4 | "label": "A collection of nonexistent items", 5 | "link": { 6 | "item": [ 7 | { 8 | "class": "dataset", 9 | "label": "A nonexistent dataset", 10 | "href": "http://example.org/dataset.json" 11 | }, 12 | { 13 | "class": "dimension", 14 | "label": "A nonexistent dimension", 15 | "href": "http://example.org/dimension.json" 16 | }, 17 | { 18 | "class": "collection", 19 | "label": "A nonexistent collection", 20 | "href": "http://example.org/collection.json" 21 | } 22 | ] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rjstat 2 | Title: Handle 'JSON-stat' Format in R 3 | Version: 0.4.3 4 | Author: Aaron Schumacher, Håkon Malmedal, Måns Magnusson 5 | Maintainer: Aaron Schumacher 6 | Description: Handle 'JSON-stat' format () in R. 7 | Not all features are supported, especially the extensive metadata 8 | features of 'JSON-stat'. 9 | License: MIT + file LICENSE 10 | Encoding: UTF-8 11 | URL: https://github.com/ajschumacher/rjstat 12 | BugReports: https://github.com/ajschumacher/rjstat/issues 13 | Imports: 14 | jsonlite (>= 0.9.8), 15 | checkmate (>= 1.7.0) 16 | Suggests: 17 | testthat (>= 1.0.0), 18 | reshape (>= 0.7) 19 | RoxygenNote: 7.2.3 20 | -------------------------------------------------------------------------------- /tests/testthat/collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "class": "collection", 4 | "label": "A collection", 5 | "link": { 6 | "item": [ 7 | { 8 | "class": "dataset", 9 | "label": "A dataset", 10 | "value": [ 11 | 1 12 | ], 13 | "id": [ 14 | "testdimension" 15 | ], 16 | "size": [ 17 | 1 18 | ], 19 | "dimension": { 20 | "testdimension": { 21 | "label": "A dimension", 22 | "category": { 23 | "index": [ 24 | "testcategory" 25 | ], 26 | "label": { 27 | "testcategory": "A category" 28 | } 29 | } 30 | } 31 | } 32 | } 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method("[",jsonstat_dataset) 4 | S3method("[<-",jsonstat_dataset) 5 | S3method("[[",jsonstat_dataset) 6 | S3method("dimnames<-",jsonstat_dataset) 7 | S3method(as.array,jsonstat_dataset) 8 | S3method(as.character,jsonstat) 9 | S3method(as.data.frame,jsonstat_dataset) 10 | S3method(as.json,jsonstat) 11 | S3method(as.vector,jsonstat_dataset) 12 | S3method(dim,jsonstat_dataset) 13 | S3method(dimnames,jsonstat_dataset) 14 | S3method(print,jsonstat) 15 | S3method(print,jsonstat_dataset) 16 | export("id<-") 17 | export("status<-") 18 | export(as.json) 19 | export(as.jsonstat) 20 | export(fromJSONstat) 21 | export(id) 22 | export(is.jsonstat) 23 | export(is.jsonstat_collection) 24 | export(is.jsonstat_dataset) 25 | export(is.jsonstat_dimension) 26 | export(status) 27 | export(toJSONstat) 28 | import(checkmate) 29 | import(jsonlite) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-jsonstat_accessors.R: -------------------------------------------------------------------------------- 1 | context("jsonstat accessors") 2 | 3 | test_that("id", { 4 | x <- as.jsonstat("oecd.json") 5 | expect_equal(id(x), c("concept", "area", "year")) 6 | expect_error(id(x) <- "Hej") 7 | id(x) <- c("1", "2", "3") 8 | expect_equal(id(x), c("1", "2", "3")) 9 | }) 10 | 11 | test_that("status", { 12 | x <- as.jsonstat("oecd.json") 13 | expect_equal(status(x)[[1]], "e") 14 | expect_equal(names(status(x))[1], "10") 15 | expect_error(status(x) <- 5) 16 | expect_error(status(x) <- c("E", "D")) 17 | expect_silent(status(x) <- "e") 18 | expect_equal(status(x), "e") 19 | vals <- list("32"="e", "42"="g", "88"="f") 20 | expect_silent(status(x) <- vals) 21 | expect_equal(status(x), vals) 22 | names(vals) <- NULL 23 | expect_error(status(x) <- vals) 24 | expect_silent(status(x) <- rep("e", length(as.vector(x)))) 25 | }) 26 | 27 | -------------------------------------------------------------------------------- /man/as.jsonstat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/jsonstat.R 3 | \name{as.jsonstat} 4 | \alias{as.jsonstat} 5 | \alias{is.jsonstat} 6 | \alias{is.jsonstat_dataset} 7 | \alias{is.jsonstat_collection} 8 | \alias{is.jsonstat_dimension} 9 | \title{Create a JSON-stat object} 10 | \usage{ 11 | as.jsonstat(x) 12 | 13 | is.jsonstat(x) 14 | 15 | is.jsonstat_dataset(x) 16 | 17 | is.jsonstat_collection(x) 18 | 19 | is.jsonstat_dimension(x) 20 | } 21 | \arguments{ 22 | \item{x}{a JSON-stat string, URL or file} 23 | } 24 | \value{ 25 | a JSON-stat object with subclass dataset, dimension or collection 26 | } 27 | \description{ 28 | Create a JSON-stat object 29 | } 30 | \examples{ 31 | file_path <- system.file("extdata", "oecd.json", package = "rjstat") 32 | x <- as.jsonstat(file_path) 33 | print(x) 34 | is.jsonstat(x) 35 | is.jsonstat_dataset(x) 36 | is.jsonstat_dimension(x) 37 | 38 | } 39 | -------------------------------------------------------------------------------- /tests/testthat/test-constructor.R: -------------------------------------------------------------------------------- 1 | context("Constructor") 2 | 3 | test_that("constructor works", { 4 | as.jsonstat("collection.json") %>% 5 | expect_class("jsonstat") %>% 6 | expect_class("jsonstat_collection") 7 | as.jsonstat("dataset.json") %>% 8 | expect_class("jsonstat") %>% 9 | expect_class("jsonstat_dataset") 10 | expect_error(as.jsonstat("notjsonstat.json")) 11 | 12 | expect_silent(as.jsonstat("oecd.json")) 13 | expect_silent(as.jsonstat("canada.json")) 14 | expect_silent(as.jsonstat("oecd-canada-col.json")) 15 | expect_silent(as.jsonstat("galicia.json")) 16 | expect_silent(as.jsonstat("order.json")) 17 | expect_silent(as.jsonstat("hierarchy.json")) 18 | expect_silent(as.jsonstat("us-gsp.json")) 19 | expect_silent(as.jsonstat("us-unr.json")) 20 | expect_silent(as.jsonstat("us-labor.json")) 21 | expect_silent(as.jsonstat("collection_sample.json")) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-input.R: -------------------------------------------------------------------------------- 1 | context("Input") 2 | 3 | non_unique <- data.frame(V1 = c("a", "a"), V2 = c("b", "b"), value = 1:2) 4 | txt <- "{\"version\":\"2.0\",\"class\":\"dataset\",\"id\":[\"V1\"],\"size\":[1],\"value\":[1],\"dimension\":{\"V1\":{\"category\":{\"index\":[\"a\"]}}}}" 5 | 6 | test_that("wrong input fails", { 7 | expect_error(toJSONstat(data.frame(value = 1, V1 = NA)), "missing values") 8 | expect_error(toJSONstat(non_unique), 9 | "non-value columns must constitute a unique ID") 10 | }) 11 | 12 | test_that("name of value column works", { 13 | df1 <- data.frame(V1 = "a", value = 1) 14 | expect_match(toJSONstat(df1), "\"value\":\\[1\\]") 15 | df2 <- data.frame(V1 = "a", v = 1) 16 | expect_match(toJSONstat(df2, value = "v"), "\"value\":\\[1\\]") 17 | }) 18 | 19 | test_that("round-trip works", { 20 | df1 <- fromJSONstat(txt) 21 | df2 <- fromJSONstat(toJSONstat(df1)) 22 | expect_equal(df1, df2) 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-values.R: -------------------------------------------------------------------------------- 1 | context("Values") 2 | 3 | test_that("values are correct", { 4 | fromJSONstat("bundle.json") %>% 5 | getElement(1) %>% 6 | getElement("value") %>% 7 | expect_equal(c(1.23456789, 2.3456789, 3.456789, 4.56789, 5.6789, 6.789)) 8 | fromJSONstat("bundle.json") %>% 9 | getElement(2) %>% 10 | getElement("value") %>% 11 | expect_equal(c(NA, 2, NA, 4)) 12 | data.frame(V1 = rev(letters), value = 1:26) %>% 13 | toJSONstat() %>% 14 | fromJSONstat() %>% 15 | getElement("value") %>% 16 | expect_equal(26:1) 17 | data.frame(V1 = 1:26, value = letters) %>% 18 | toJSONstat() %>% 19 | fromJSONstat() %>% 20 | getElement("value") %>% 21 | expect_equal(letters) 22 | data.frame(V1 = 0:255, value = as.raw(0:255)) %>% 23 | toJSONstat() %>% 24 | fromJSONstat() %>% 25 | getElement("value") %>% 26 | expect_equal(as.character(as.raw(0:255))) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/order.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "dataset", 4 | "href" : "https://json-stat.org/samples/order.json", 5 | "label" : "Demo of value ordering: what does not change, first", 6 | "id" : ["A","B","C"], 7 | "size" : [3,2,4], 8 | "dimension" : { 9 | "A" : { 10 | "label" : "A: 3-categories dimension", 11 | "category" : { 12 | "index" : ["1", "2", "3"] 13 | } 14 | }, 15 | "B" : { 16 | "label" : "B: 2-categories dimension", 17 | "category" : { 18 | "index" : ["1", "2"] 19 | } 20 | } , 21 | "C" : { 22 | "label" : "C: 4-categories dimension", 23 | "category" : { 24 | "index" : ["1", "2", "3", "4"] 25 | } 26 | } 27 | }, 28 | "value" : [ 29 | "A1B1C1","A1B1C2","A1B1C3","A1B1C4", 30 | "A1B2C1","A1B2C2","A1B2C3","A1B2C4", 31 | 32 | "A2B1C1","A2B1C2","A2B1C3","A1B1C4", 33 | "A2B2C1","A2B2C2","A2B2C3","A2B2C4", 34 | 35 | "A3B1C1","A3B1C2","A3B1C3","A3B1C4", 36 | "A3B2C1","A3B2C2","A3B2C3","A3B2C4" 37 | ] 38 | } -------------------------------------------------------------------------------- /man/fromJSONstat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rjstat.R 3 | \name{fromJSONstat} 4 | \alias{fromJSONstat} 5 | \title{Convert JSON-stat format to data frame(s)} 6 | \usage{ 7 | fromJSONstat(x, naming = "label", use_factors = FALSE, silent = FALSE) 8 | } 9 | \arguments{ 10 | \item{x}{JSON-stat format response, or path or URL to such a response} 11 | 12 | \item{naming}{whether to use (longer) \code{label}s or (shorter) \code{id}s} 13 | 14 | \item{use_factors}{whether dimension categories should be factors or 15 | character objects} 16 | 17 | \item{silent}{suppress warnings} 18 | } 19 | \value{ 20 | For responses with class \code{dataset}: A data frame. For responses 21 | with class \code{collection}: An unnamed list of one or more lists or data 22 | frames. For responses with class \code{bundle}: A named list of one or more 23 | data frames. 24 | } 25 | \description{ 26 | This function takes a JSON-stat format response and returns a data frame or a 27 | list of data frames, with columns for each dimension and one \code{value} 28 | column. 29 | } 30 | \examples{ 31 | \dontrun{ 32 | oecd.canada.url <- "https://json-stat.org/samples/oecd-canada.json" 33 | results <- fromJSONstat(oecd.canada.url) 34 | names(results) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /man/toJSONstat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rjstat.R 3 | \name{toJSONstat} 4 | \alias{toJSONstat} 5 | \title{Convert data frame(s) to JSON-stat format} 6 | \usage{ 7 | toJSONstat(x, value = "value", ...) 8 | } 9 | \arguments{ 10 | \item{x}{a data frame or list of data frames} 11 | 12 | \item{value}{name of value column} 13 | 14 | \item{...}{arguments passed on to \code{\link[jsonlite]{toJSON}}} 15 | } 16 | \value{ 17 | For a data frame: A JSON-stat format response with class 18 | \code{dataset}. For a list of data frames: A JSON-stat format response with 19 | class \code{collection}. 20 | } 21 | \description{ 22 | This function takes a data frame or list of data frames and returns 23 | a string representation in JSON-stat format. The input data frame(s) 24 | must be in maximally long tidy format: with only one \code{value} 25 | column and all other columns representing dimensions. 26 | } 27 | \examples{ 28 | library(reshape) 29 | irises <- melt(cbind(iris, Specimen=rep(1:50, 3)), 30 | id.vars=c("Species", "Specimen")) 31 | irisJSONstat <- toJSONstat(list(iris=irises)) 32 | cat(substr(irisJSONstat, 1, 76)) 33 | 34 | # Add indentation whitespace 35 | toJSONstat(as.data.frame(Titanic), value = "Freq", pretty = TRUE) 36 | } 37 | -------------------------------------------------------------------------------- /tests/testthat/collection_sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "collection", 4 | "href" : "https://json-stat.org/samples/collection.json", 5 | "label" : "JSON-stat Dataset Sample Collection", 6 | "updated" : "2015-12-21", 7 | "link" : { 8 | "item" : [ 9 | { 10 | "class" : "dataset", 11 | "href" : "https://json-stat.org/samples/oecd.json", 12 | "label" : "Unemployment rate in the OECD countries 2003-2014" 13 | }, 14 | { 15 | "class" : "dataset", 16 | "href" : "https://json-stat.org/samples/canada.json", 17 | "label" : "Population by sex and age group. Canada. 2012" 18 | }, 19 | { 20 | "class" : "dataset", 21 | "href" : "https://json-stat.org/samples/galicia.json", 22 | "label" : "Population by province of residence, place of birth, age, gender and year in Galicia" 23 | }, 24 | { 25 | "class" : "dataset", 26 | "href" : "https://json-stat.org/samples/us-gsp.json", 27 | "label" : "US States by GSP and population" 28 | }, 29 | { 30 | "class" : "dataset", 31 | "href" : "https://json-stat.org/samples/us-unr.json", 32 | "label" : "Unemployment Rates by County, 2012 Annual Averages" 33 | }, 34 | { 35 | "class" : "dataset", 36 | "href" : "https://json-stat.org/samples/us-labor.json", 37 | "label" : "Labor Force Data by County, 2012 Annual Averages" 38 | }, 39 | { 40 | "class" : "dataset", 41 | "href" : "https://json-stat.org/samples/order.json", 42 | "label" : "Demo of value ordering: what does not change, first" 43 | }, 44 | { 45 | "class" : "dataset", 46 | "href" : "https://json-stat.org/samples/hierarchy.json", 47 | "label" : "Demo of hierarchical dimension" 48 | } 49 | ] 50 | } 51 | } -------------------------------------------------------------------------------- /R/jsonstat.R: -------------------------------------------------------------------------------- 1 | #' Create a JSON-stat object 2 | #' 3 | #' @param x a JSON-stat string, URL or file 4 | #' 5 | #' @return a JSON-stat object with subclass dataset, dimension or collection 6 | #' 7 | #' @examples 8 | #' file_path <- system.file("extdata", "oecd.json", package = "rjstat") 9 | #' x <- as.jsonstat(file_path) 10 | #' print(x) 11 | #' is.jsonstat(x) 12 | #' is.jsonstat_dataset(x) 13 | #' is.jsonstat_dimension(x) 14 | #' 15 | #' @export 16 | as.jsonstat <- function(x){ 17 | x <- fromJSON(x, simplifyDataFrame = FALSE) 18 | x <- parse_value(x) 19 | validate_jsonstat(x) 20 | class(x) <- c(paste0("jsonstat_", x$class), "jsonstat", "list") 21 | x 22 | } 23 | 24 | #' @rdname as.jsonstat 25 | #' @export 26 | is.jsonstat <- function(x){ 27 | inherits(x, "jsonstat") 28 | } 29 | 30 | #' @rdname as.jsonstat 31 | #' @export 32 | is.jsonstat_dataset <- function(x){ 33 | inherits(x, "jsonstat_dataset") 34 | } 35 | 36 | #' @rdname as.jsonstat 37 | #' @export 38 | is.jsonstat_collection <- function(x){ 39 | inherits(x, "jsonstat_collection") 40 | } 41 | 42 | #' @rdname as.jsonstat 43 | #' @export 44 | is.jsonstat_dimension <- function(x){ 45 | inherits(x, "jsonstat_dimension") 46 | } 47 | 48 | parse_value <- function(x){ 49 | if(!is.null(names(x$value))){ 50 | idx <- as.integer(names(x$value)) + 1 51 | vals <- unlist(x$value) 52 | x$value <- rep(NA, prod(x$size)) 53 | if(length(vals) > 0) x$value[idx] <- vals 54 | } 55 | x 56 | } 57 | 58 | #' Function to validate json stat 59 | #' 60 | #' @description 61 | #' Now this is just a simple light-weight validation. 62 | #' Hopefully this can be complemented with a real json stat 63 | #' schema validator. 64 | #' 65 | #' @keywords internal 66 | validate_jsonstat <- function(x){ 67 | assert_subset(c("class", "version"), names(x)) 68 | assert_set_equal(x$version, "2.0") 69 | assert_subset(x$class, c("dataset", "dimension", "collection")) 70 | } 71 | 72 | 73 | -------------------------------------------------------------------------------- /R/jsonstat_accessors.R: -------------------------------------------------------------------------------- 1 | #' \code{id} accessors of \code{jsonstat} objects 2 | #' 3 | #' @description 4 | #' Access and change \code{id}s of jsonstat objects. 5 | #' 6 | #' @param x a \code{jsonstat_dataset} object 7 | #' @param value a character vector of up to the same length as \code{id(x)}. 8 | #' 9 | #' @export 10 | id <- function(x){ 11 | assert_class(x, "jsonstat_dataset") 12 | x$id 13 | } 14 | 15 | #' @rdname id 16 | #' @export 17 | `id<-` <- function(x, value){ 18 | assert_class(x, "jsonstat_dataset") 19 | assert_character(value,len = length(id(x))) 20 | names(value) <- id(x) 21 | x$id <- as.vector(value) 22 | names(x$dimension) <- as.vector(value[names(x$dimension)]) 23 | x 24 | } 25 | 26 | 27 | #' \code{status} accessors of \code{jsonstat} objects 28 | #' 29 | #' @description 30 | #' Access and change \code{status}s of jsonstat objects. 31 | #' 32 | #' @param x a \code{jsonstat_dataset} object 33 | #' @param value a character vector of up to the same length as \code{as.vector(x)} or a named list with index as vector names. 34 | #' 35 | #' @export 36 | status <- function(x){ 37 | assert_class(x, "jsonstat_dataset") 38 | x$status 39 | } 40 | 41 | #' @rdname status 42 | #' @export 43 | `status<-` <- function(x, value){ 44 | assert_class(x, "jsonstat_dataset") 45 | stopifnot(is.list(value) | is.character(value)) 46 | max_len <- length(as.vector(x)) 47 | if(is.list(value)){ 48 | if(!is.null(names(value))){ 49 | assert_subset(names(value), as.character(1:max_len)) 50 | x$status <- value 51 | } else { 52 | stop("Not a named list! Use a character vector instead.") 53 | } 54 | } 55 | if(is.character(value)){ 56 | if(length(value) == 1) { 57 | x$status <- value 58 | } else if(length(value) == max_len) { 59 | x$status <- value 60 | } else { 61 | stop("Not a correct length of 'value'.") 62 | } 63 | } 64 | x 65 | } 66 | 67 | 68 | -------------------------------------------------------------------------------- /tests/testthat/bundle.json: -------------------------------------------------------------------------------- 1 | { 2 | "dataset": { 3 | "label": "A dataset with array value", 4 | "source": "Random data", 5 | "updated": "2014-09-29", 6 | "value": [ 7 | 1.23456789, 8 | 2.3456789, 9 | 3.456789, 10 | 4.56789, 11 | 5.6789, 12 | 6.789 13 | ], 14 | "dimension": { 15 | "id": [ 16 | "testdimension1", 17 | "testdimension2", 18 | "testdimension3" 19 | ], 20 | "size": [ 21 | 2, 22 | 3, 23 | 1 24 | ], 25 | "testdimension1": { 26 | "label": "A dimension with array index", 27 | "category": { 28 | "index": [ 29 | "testcategory11", 30 | "testcategory12" 31 | ], 32 | "label": { 33 | "testcategory12": "Category 12", 34 | "testcategory11": "Category 11" 35 | } 36 | } 37 | }, 38 | "testdimension2": { 39 | "label": "A dimension with object index", 40 | "category": { 41 | "index": { 42 | "testcategory23": 2, 43 | "testcategory21": 0, 44 | "testcategory22": 1 45 | }, 46 | "label": { 47 | "testcategory22": "Category 22", 48 | "testcategory23": "Category 23", 49 | "testcategory21": "Category 21" 50 | } 51 | } 52 | }, 53 | "testdimension3": { 54 | "label": "A dimension without index", 55 | "category": { 56 | "label": { 57 | "testcategory3": "Category 3" 58 | } 59 | } 60 | } 61 | } 62 | }, 63 | "dataset2": { 64 | "label": "A dataset with object value", 65 | "value": { 66 | "3": 4, 67 | "1": 2, 68 | "0": null 69 | }, 70 | "dimension": { 71 | "id": [ 72 | "testdimension" 73 | ], 74 | "size": [ 75 | 4 76 | ], 77 | "testdimension": { 78 | "label": "A dimension", 79 | "category": { 80 | "index": [ 81 | "testcategory1", 82 | "testcategory2", 83 | "testcategory3", 84 | "testcategory4" 85 | ], 86 | "label": { 87 | "testcategory1": "Category 1", 88 | "testcategory2": "Category 2", 89 | "testcategory3": "Category 3", 90 | "testcategory4": "Category 4" 91 | } 92 | } 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rjstat: read and write JSON-stat with R 2 | [![Build Status](https://app.travis-ci.com/ajschumacher/rjstat.svg?branch=master)](https://app.travis-ci.com/ajschumacher/rjstat) [![Coverage Status](https://coveralls.io/repos/github/MansMeg/rjstat/badge.svg?branch=master)](https://coveralls.io/github/MansMeg/rjstat?branch=master) [![rstudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/rjstat)](https://github.com/r-hub/cranlogs.app) 3 | [![cran version](https://www.r-pkg.org/badges/version/rjstat)](https://CRAN.R-project.org/package=rjstat) 4 | 5 | Read and write data sets in the [JSON-stat](https://json-stat.org/) format. 6 | 7 | 8 | ### Installation: 9 | 10 | [From CRAN](https://cran.r-project.org/package=rjstat) (most people use this): 11 | 12 | ```s 13 | install.packages('rjstat') 14 | ``` 15 | 16 | [From github](https://github.com/ajschumacher/rjstat) (development version): 17 | 18 | ```s 19 | library(devtools) 20 | install_github("ajschumacher/rjstat") 21 | ``` 22 | 23 | 24 | ### Usage: 25 | 26 | ```s 27 | library(rjstat) 28 | 29 | oecd.canada.url <- "https://json-stat.org/samples/oecd-canada.json" 30 | 31 | # Read from JSON-stat to a list of data frames: 32 | results <- fromJSONstat(readLines(oecd.canada.url)) 33 | names(results) 34 | 35 | ## [1] "Unemployment rate in the OECD countries 2003-2014" 36 | ## [2] "Population by sex and age group. Canada. 2012" 37 | 38 | # You can also read in using the typically terser IDs rather than labels. 39 | results <- fromJSONstat(readLines(oecd.canada.url), naming="id") 40 | names(results) 41 | 42 | ## [1] "oecd" "canada" 43 | 44 | 45 | # Convert from a list of data frames to a JSON-stat string. 46 | # (The data frames must have exactly one value column.) 47 | library(reshape) 48 | irises <- melt(cbind(iris, Specimen=rep(1:50, 3)), 49 | id.vars=c("Species", "Specimen")) 50 | irisJSONstat <- toJSONstat(list(iris=irises)) 51 | cat(substr(irisJSONstat, 1, 76)) 52 | 53 | ## {"version":"2.0","class":"collection","link":{"item":[{"class":"dataset","id 54 | 55 | # You can successfully convert back and forth, but only for the features that 56 | # make sense in both R and JSON-stat. 57 | head(fromJSONstat(irisJSONstat)[[1]]) 58 | 59 | ## Species Specimen variable value 60 | ## 1 setosa 1 Sepal.Length 5.1 61 | ## 2 setosa 1 Sepal.Width 3.5 62 | ## 3 setosa 1 Petal.Length 1.4 63 | ## 4 setosa 1 Petal.Width 0.2 64 | ## 5 setosa 2 Sepal.Length 4.9 65 | ## 6 setosa 2 Sepal.Width 3.0 66 | ``` 67 | -------------------------------------------------------------------------------- /tests/testthat/test-output.R: -------------------------------------------------------------------------------- 1 | context("Output") 2 | 3 | test_that("single-dimension input gives correct output", { 4 | txt <- "{\"version\":\"2.0\",\"class\":\"dataset\",\"id\":[\"V1\"],\"size\":[1],\"value\":[1],\"dimension\":{\"V1\":{\"category\":{\"index\":[\"a\"]}}}}" 5 | expect_identical(toJSONstat(data.frame(V1 = "a", value = 1)), 6 | structure(txt, class = "json")) 7 | }) 8 | 9 | test_that("sparse cubes give correct output", { 10 | txt <- "{\"version\":\"2.0\",\"class\":\"dataset\",\"id\":[\"V1\",\"V2\"],\"size\":[2,2],\"value\":{\"0\":1,\"3\":2},\"dimension\":{\"V1\":{\"category\":{\"index\":[\"a\",\"b\"]}},\"V2\":{\"category\":{\"index\":[\"A\",\"B\"]}}}}" 11 | expect_identical(toJSONstat(data.frame(V1 = c("a", "b"), V2 = c("A", "B"), 12 | value = 1:2)), 13 | structure(txt, class = "json")) 14 | expect_equal(fromJSONstat(txt), 15 | data.frame(V1 = c("a", "a", "b", "b"), 16 | V2 = c("A", "B", "A", "B"), 17 | value = c(1, NA, NA, 2), 18 | stringsAsFactors = FALSE)) 19 | txt2 <- "{\"version\":\"2.0\",\"class\":\"dataset\",\"id\":[\"V1\",\"V2\"],\"size\":[2,2],\"value\":{\"0\":true,\"3\":false},\"dimension\":{\"V1\":{\"category\":{\"index\":[\"a\",\"b\"]}},\"V2\":{\"category\":{\"index\":[\"A\",\"B\"]}}}}" 20 | expect_identical(toJSONstat(data.frame(V1 = c("a", "b"), V2 = c("A", "B"), 21 | value = c(TRUE, FALSE))), 22 | structure(txt2, class = "json")) 23 | expect_equal(fromJSONstat(txt2), 24 | data.frame(V1 = c("a", "a", "b", "b"), 25 | V2 = c("A", "B", "A", "B"), 26 | value = c(TRUE, NA, NA, FALSE), 27 | stringsAsFactors = FALSE)) 28 | }) 29 | 30 | test_that("value objects give correct output", { 31 | df1 <- data.frame(V1 = factor(letters[1], letters), value = 1) 32 | txt1 <- toJSONstat(df1) 33 | expect_equal(fromJSONstat(txt1, use_factors = TRUE), 34 | data.frame(V1 = letters, 35 | value = c(1, rep(NA, 25)), 36 | stringsAsFactors = TRUE)) 37 | df2 <- data.frame(V1 = factor(letters[1:2], letters), value = 1:2) 38 | txt2 <- toJSONstat(df2) 39 | expect_equal(fromJSONstat(txt2, use_factors = TRUE), 40 | data.frame(V1 = letters, 41 | value = c(1:2, rep(NA, 24)), 42 | stringsAsFactors = TRUE)) 43 | }) 44 | 45 | test_that("named and unnamed lists give the same output", { 46 | d <- cbind(expand.grid(letters, LETTERS), value = seq_len(676)) 47 | expect_equal(toJSONstat(list(d)), toJSONstat(list(d = d))) 48 | }) 49 | -------------------------------------------------------------------------------- /tests/testthat/test-factors.R: -------------------------------------------------------------------------------- 1 | context("Factors") 2 | 3 | test_that("factors are factors", { 4 | fromJSONstat("bundle.json", naming = "label", use_factors = TRUE) %>% 5 | getElement(1) %>% 6 | getElement(1) %>% 7 | expect_s3_class("factor") 8 | fromJSONstat("bundle.json", naming = "id", use_factors = TRUE) %>% 9 | getElement(1) %>% 10 | getElement(1) %>% 11 | expect_s3_class("factor") 12 | 13 | fromJSONstat("bundle.json", naming = "label", use_factors = TRUE) %>% 14 | getElement(1) %>% 15 | getElement(2) %>% 16 | expect_s3_class("factor") 17 | fromJSONstat("bundle.json", naming = "id", use_factors = TRUE) %>% 18 | getElement(1) %>% 19 | getElement(2) %>% 20 | expect_s3_class("factor") 21 | 22 | fromJSONstat("bundle.json", naming = "label", use_factors = TRUE) %>% 23 | getElement(1) %>% 24 | getElement(3) %>% 25 | expect_s3_class("factor") 26 | fromJSONstat("bundle.json", naming = "id", use_factors = TRUE) %>% 27 | getElement(1) %>% 28 | getElement(3) %>% 29 | expect_s3_class("factor") 30 | }) 31 | 32 | test_that("factor levels are correct", { 33 | fromJSONstat("bundle.json", naming = "label", use_factors = TRUE) %>% 34 | getElement(1) %>% 35 | getElement(1) %>% 36 | levels() %>% 37 | expect_equal(c("Category 11", "Category 12")) 38 | fromJSONstat("bundle.json", naming = "id", use_factors = TRUE) %>% 39 | getElement(1) %>% 40 | getElement(1) %>% 41 | levels() %>% 42 | expect_equal(c("testcategory11", "testcategory12")) 43 | 44 | fromJSONstat("bundle.json", naming = "label", use_factors = TRUE) %>% 45 | getElement(1) %>% 46 | getElement(2) %>% 47 | levels() %>% 48 | expect_equal(c("Category 21", "Category 22", "Category 23")) 49 | fromJSONstat("bundle.json", naming = "id", use_factors = TRUE) %>% 50 | getElement(1) %>% 51 | getElement(2) %>% 52 | levels() %>% 53 | expect_equal(c("testcategory21", "testcategory22", "testcategory23")) 54 | 55 | fromJSONstat("bundle.json", naming = "label", use_factors = TRUE) %>% 56 | getElement(1) %>% 57 | getElement(3) %>% 58 | levels() %>% 59 | expect_equal("Category 3") 60 | fromJSONstat("bundle.json", naming = "id", use_factors = TRUE) %>% 61 | getElement(1) %>% 62 | getElement(3) %>% 63 | levels() %>% 64 | expect_equal("testcategory3") 65 | }) 66 | 67 | test_that("factor integer codes are correct", { 68 | fromJSONstat("bundle.json", use_factors = TRUE) %>% 69 | getElement(1) %>% 70 | getElement(1) %>% 71 | unclass() %>% 72 | expect_equivalent(c(1, 1, 1, 2, 2, 2)) 73 | fromJSONstat("bundle.json", use_factors = TRUE) %>% 74 | getElement(1) %>% 75 | getElement(2) %>% 76 | unclass() %>% 77 | expect_equivalent(c(1, 2, 3, 1, 2, 3)) 78 | fromJSONstat("bundle.json", use_factors = TRUE) %>% 79 | getElement(1) %>% 80 | getElement(3) %>% 81 | unclass() %>% 82 | expect_equivalent(c(1, 1, 1, 1, 1, 1)) 83 | }) 84 | -------------------------------------------------------------------------------- /tests/testthat/test-columns.R: -------------------------------------------------------------------------------- 1 | context("Columns") 2 | 3 | test_that("column names are correct", { 4 | fromJSONstat("bundle.json", naming = "label") %>% 5 | getElement(1) %>% 6 | expect_named(c("A dimension with array index", 7 | "A dimension with object index", 8 | "A dimension without index", "value")) 9 | fromJSONstat("bundle.json", naming = "id") %>% 10 | getElement(1) %>% 11 | expect_named(c("testdimension1", "testdimension2", 12 | "testdimension3", "value")) 13 | data.frame(V1 = "a", value = 1) %>% 14 | toJSONstat(value = "V1") %>% 15 | fromJSONstat() %>% 16 | expect_named(c("value", "value")) 17 | readLines("bundle.json") %>% 18 | gsub(pattern = " with[^\"]*", replacement = "") %>% 19 | fromJSONstat() %>% 20 | getElement(1) %>% 21 | expect_named(c(rep("A dimension", 3), "value")) 22 | }) 23 | 24 | test_that("columns are correct", { 25 | fromJSONstat("bundle.json", naming = "label") %>% 26 | getElement(1) %>% 27 | getElement(1) %>% 28 | expect_equal(c("Category 11", "Category 11", "Category 11", 29 | "Category 12", "Category 12", "Category 12")) 30 | fromJSONstat("bundle.json", naming = "id") %>% 31 | getElement(1) %>% 32 | getElement(1) %>% 33 | expect_equal(c("testcategory11", "testcategory11", "testcategory11", 34 | "testcategory12", "testcategory12", "testcategory12")) 35 | 36 | fromJSONstat("bundle.json", naming = "label") %>% 37 | getElement(1) %>% 38 | getElement(2) %>% 39 | expect_equal(c("Category 21", "Category 22", "Category 23", 40 | "Category 21", "Category 22", "Category 23")) 41 | fromJSONstat("bundle.json", naming = "id") %>% 42 | getElement(1) %>% 43 | getElement(2) %>% 44 | expect_equal(c("testcategory21", "testcategory22", "testcategory23", 45 | "testcategory21", "testcategory22", "testcategory23")) 46 | 47 | fromJSONstat("bundle.json", naming = "label") %>% 48 | getElement(1) %>% 49 | getElement(3) %>% 50 | expect_equal(c("Category 3", "Category 3", "Category 3", 51 | "Category 3", "Category 3", "Category 3")) 52 | fromJSONstat("bundle.json", naming = "id") %>% 53 | getElement(1) %>% 54 | getElement(3) %>% 55 | expect_equal(c("testcategory3", "testcategory3", "testcategory3", 56 | "testcategory3", "testcategory3", "testcategory3")) 57 | 58 | data.frame(V1 = as.raw(0:255), value = 0:255) %>% 59 | toJSONstat() %>% 60 | fromJSONstat() %>% 61 | getElement("V1") %>% 62 | expect_equal(sort(as.character(as.raw(0:255)))) 63 | }) 64 | 65 | test_that("column names are correct for missing labels", { 66 | readLines("bundle.json")[-26] %>% 67 | fromJSONstat(naming = "label") %>% 68 | getElement(1) %>% 69 | expect_named(c("testdimension1", "A dimension with object index", 70 | "A dimension without index", "value")) 71 | }) 72 | 73 | test_that("columns are correct for missing labels", { 74 | readLines("bundle.json")[-33] %>% 75 | fromJSONstat(naming = "label") %>% 76 | getElement(1) %>% 77 | getElement(1) %>% 78 | expect_equal(c("testcategory11", "testcategory11", "testcategory11", 79 | "testcategory12", "testcategory12", "testcategory12")) 80 | readLines("bundle.json")[-47] %>% 81 | fromJSONstat(naming = "label") %>% 82 | getElement(1) %>% 83 | getElement(2) %>% 84 | expect_equal(c("testcategory21", "testcategory22", "testcategory23", 85 | "testcategory21", "testcategory22", "testcategory23")) 86 | }) 87 | -------------------------------------------------------------------------------- /tests/testthat/canada.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "dataset", 4 | "href" : "https://json-stat.org/samples/canada.json", 5 | "label" : "Population by sex and age group. Canada. 2012", 6 | "source" : "Statistics Canada, CANSIM, table 051-0001", 7 | "updated" : "2012-09-27", 8 | "value" : [34880.5, 17309.1, 17571.3, 100.0, 100.0, 100.0, 1928.8, 988.7, 940.1, 5.5, 5.7, 5.3, 1857.1, 955.0, 902.1, 5.3, 5.5, 5.1, 1877.3, 964.7, 912.6, 5.4, 5.6, 5.2, 2163.0, 1108.2, 1054.7, 6.2, 6.4, 6.0, 2441.1, 1254.2, 1186.9, 7.0, 7.2, 6.8, 2452.3, 1246.8, 1205.5, 7.0, 7.2, 6.9, 2406.3, 1203.5, 1202.8, 6.9, 7.0, 6.8, 2307.2, 1155.2, 1152.0, 6.6, 6.7, 6.6, 2384.6, 1199.4, 1185.2, 6.8, 6.9, 6.7, 2681.3, 1350.1, 1331.2, 7.7, 7.8, 7.6, 2703.2, 1352.3, 1350.9, 7.7, 7.8, 7.7, 2428.5, 1199.0, 1229.5, 7.0, 6.9, 7.0, 2063.0, 1010.2, 1052.8, 5.9, 5.8, 6.0, 1645.1, 797.9, 847.2, 4.7, 4.6, 4.8, 1190.7, 563.8, 626.8, 3.4, 3.3, 3.6, 924.1, 418.9, 505.2, 2.6, 2.4, 2.9, 718.8, 303.6, 415.2, 2.1, 1.8, 2.4, 451.0, 164.1, 286.9, 1.3, 0.9, 1.6, 257.1, 73.2, 183.9, 0.7, 0.4, 1.0], 9 | "status" : ["a"], 10 | "id" : ["country", "year", "age", "concept", "sex"], 11 | "size" : [1, 1, 20, 2, 3], 12 | "role" :{ 13 | "time" : ["year"], 14 | "geo" : ["country"], 15 | "metric" : ["concept"] 16 | }, 17 | "dimension" : { 18 | "concept" : { 19 | "label" : "concepts", 20 | "category" : { 21 | "index" : { 22 | "POP" : 0, 23 | "PERCENT" : 1 24 | }, 25 | "label" : { 26 | "POP" : "population", 27 | "PERCENT" : "weight of age group in the population" 28 | }, 29 | "unit" : { 30 | "POP" : { 31 | "label": "thousands of persons", 32 | "decimals": 1, 33 | "position" : "end", 34 | "type" : "count", 35 | "base" : "people", 36 | "multiplier" : 3 37 | }, 38 | "PERCENT" : { 39 | "label" : "%", 40 | "decimals": 1, 41 | "position" : "end", 42 | "type" : "ratio", 43 | "base" : "per cent", 44 | "multiplier" : 0 45 | } 46 | } 47 | } 48 | }, 49 | 50 | "year" : { 51 | "label" : "year", 52 | "category" : { 53 | "index" : { 54 | "2012" : 0 55 | } 56 | } 57 | }, 58 | 59 | "country" : { 60 | "label" : "country", 61 | "category" : { 62 | "label" : { 63 | "CA" : "Canada" 64 | } 65 | } 66 | }, 67 | 68 | "age" : { 69 | "label" : "age group", 70 | "category" : { 71 | "index" : [ 72 | "T", 73 | "4", 74 | "9", 75 | "14", 76 | "19", 77 | "24", 78 | "29", 79 | "34", 80 | "39", 81 | "44", 82 | "49", 83 | "54", 84 | "59", 85 | "64", 86 | "69", 87 | "74", 88 | "79", 89 | "84", 90 | "89", 91 | "older" 92 | ], 93 | "label" : { 94 | "T": "total", 95 | "4": "0 to 4", 96 | "9": "5 to 9", 97 | "14": "10 to 14", 98 | "19": "15 to 19", 99 | "24": "20 to 24", 100 | "29": "25 to 29", 101 | "34": "30 to 34", 102 | "39": "35 to 39", 103 | "44": "40 to 44", 104 | "49": "45 to 49", 105 | "54": "50 to 54", 106 | "59": "55 to 59", 107 | "64": "60 to 64", 108 | "69": "65 to 69", 109 | "74": "70 to 74", 110 | "79": "75 to 79", 111 | "84": "80 to 84", 112 | "89": "85 to 89", 113 | "older": "90 and older" 114 | } 115 | } 116 | }, 117 | 118 | "sex" : { 119 | "label" : "sex", 120 | 121 | "link" : { 122 | "alternate" : [ 123 | { 124 | "type" : "text/html", 125 | "href" : "http://www.statcan.gc.ca/concepts/definitions/class-sex-eng.htm" 126 | } 127 | ] 128 | }, 129 | "category" : { 130 | "index" : ["T", "M", "F"], 131 | "label" : { 132 | "T" : "total", 133 | "M" : "male", 134 | "F" : "female" 135 | } 136 | } 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /tests/testthat/us-gsp.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "dataset", 4 | "href" : "https://json-stat.org/samples/us-gsp.json", 5 | "label" : "US States by GSP and population", 6 | "source" : "Wikipedia (usgovernmentrevenue.com)", 7 | "updated" : "2013-10-03", 8 | "value" : [ 9 | 174400,1.2,4.8,36333, 10 | 45600,0.31,0.7,65143, 11 | 261300,1.8,6.4,40828, 12 | 105800,0.73,2.9,36483, 13 | 2080600,13.34,37.3,51914, 14 | 259700,1.79,5,51940, 15 | 233400,1.61,3.6,64833, 16 | 62700,0.43,0.9,69667, 17 | 104700,0.72,0.6,174500, 18 | 754000,5.2,18.8,40106, 19 | 403100,2.79,9.7,41711, 20 | 68900,0.47,1.4,49214, 21 | 54800,0.38,1.6,34250, 22 | 644200,4.44,12.8,50328, 23 | 267600,1.84,6.5,41169, 24 | 147200,1.01,3,49067, 25 | 128500,0.89,2.9,44310, 26 | 161400,1.11,4.3,37535, 27 | 213600,1.47,4.5,47467, 28 | 53200,0.37,1.3,40923, 29 | 300000,2.07,5.8,51724, 30 | 377700,2.6,6.5,58108, 31 | 372400,2.57,9.9,37616, 32 | 267100,1.84,5.3,50396, 33 | 98900,0.68,3,32967, 34 | 246700,1.7,6,41117, 35 | 37200,0.26,1,37200, 36 | 89600,0.62,1.8,49778, 37 | 127500,0.88,2.7,47222, 38 | 61600,0.42,1.3,47385, 39 | 497000,3.42,8.8,56477, 40 | 75500,0.52,2.1,35952, 41 | 1156500,7.68,19.4,57423, 42 | 407400,2.81,9.5,42884, 43 | 33400,0.23,0.7,47714, 44 | 483400,3.33,11.5,42035, 45 | 160500,1.11,3.8,42237, 46 | 168900,1.16,3.8,44447, 47 | 575600,3.97,12.7,45323, 48 | 49500,0.34,1.1,45000, 49 | 164300,1.13,4.6,35717, 50 | 39900,0.27,0.8,49875, 51 | 250300,1.72,6.3,39730, 52 | 1458300,8.92,25.1,58099, 53 | 116900,0.81,2.8,41750, 54 | 26400,0.18,0.6,44000, 55 | 427700,2.95,8,53463, 56 | 351100,2.42,6.7,52403, 57 | 66600,0.46,1.9,35053, 58 | 251400,1.73,5.7,44105, 59 | 38200,0.26,0.6,63667 60 | ], 61 | "id" : ["year", "state", "concept"], 62 | "size" : [1, 51, 4], 63 | "role" :{ 64 | "time" : ["year"], 65 | "geo" : ["state"], 66 | "metric" : ["concept"] 67 | }, 68 | "dimension" : { 69 | "concept" : { 70 | "label" : "concepts", 71 | "category" : { 72 | "index" : { 73 | "gsp" : 0, 74 | "perc" : 1, 75 | "pop": 2, 76 | "capita": 3 77 | }, 78 | "label" : { 79 | "gsp" : "Gross State Product", 80 | "perc" : "Gross State Product as percentage of national GDP", 81 | "pop": "population", 82 | "capita": "Gross State Product per capita" 83 | }, 84 | "unit" : { 85 | "gsp" : { 86 | "symbol" : "$", 87 | "position" : "start", 88 | "label": "million", 89 | "multiplier": 6, 90 | "decimals": 0 91 | }, 92 | "perc" : { 93 | "symbol" : "%", 94 | "position" : "end", 95 | "multiplier": 0, 96 | "decimals": 2 97 | }, 98 | "pop" : { 99 | "label": "million", 100 | "multiplier": 6, 101 | "decimals": 1 102 | }, 103 | "capita" : { 104 | "symbol" : "$", 105 | "position" : "start", 106 | "multiplier": 0, 107 | "decimals": 0 108 | } 109 | } 110 | } 111 | }, 112 | 113 | "year" : { 114 | "label" : "year", 115 | "category" : { 116 | "index" : { 117 | "2013" : 0 118 | } 119 | } 120 | }, 121 | 122 | "state" : { 123 | "label" : "state", 124 | "category" : { 125 | "index" : { 126 | "01": 0, 127 | "02": 1, 128 | "04": 2, 129 | "05": 3, 130 | "06": 4, 131 | "08": 5, 132 | "09": 6, 133 | "10": 7, 134 | "11": 8, 135 | "12": 9, 136 | "13": 10, 137 | "15": 11, 138 | "16": 12, 139 | "17": 13, 140 | "18": 14, 141 | "19": 15, 142 | "20": 16, 143 | "21": 17, 144 | "22": 18, 145 | "23": 19, 146 | "24": 20, 147 | "25": 21, 148 | "26": 22, 149 | "27": 23, 150 | "28": 24, 151 | "29": 25, 152 | "30": 26, 153 | "31": 27, 154 | "32": 28, 155 | "33": 29, 156 | "34": 30, 157 | "35": 31, 158 | "36": 32, 159 | "37": 33, 160 | "38": 34, 161 | "39": 35, 162 | "40": 36, 163 | "41": 37, 164 | "42": 38, 165 | "44": 39, 166 | "45": 40, 167 | "46": 41, 168 | "47": 42, 169 | "48": 43, 170 | "49": 44, 171 | "50": 45, 172 | "51": 46, 173 | "53": 47, 174 | "54": 48, 175 | "55": 49, 176 | "56": 50 177 | }, 178 | "label" : { 179 | "01": "Alabama", 180 | "02": "Alaska", 181 | "04": "Arizona", 182 | "05": "Arkansas", 183 | "06": "California", 184 | "08": "Colorado", 185 | "09": "Connecticut", 186 | "10": "Delaware", 187 | "11": "District of Columbia", 188 | "12": "Florida", 189 | "13": "Georgia", 190 | "15": "Hawaii", 191 | "16": "Idaho", 192 | "17": "Illinois", 193 | "18": "Indiana", 194 | "19": "Iowa", 195 | "20": "Kansas", 196 | "21": "Kentucky", 197 | "22": "Louisiana", 198 | "23": "Maine", 199 | "24": "Maryland", 200 | "25": "Massachusetts", 201 | "26": "Michigan", 202 | "27": "Minnesota", 203 | "28": "Mississippi", 204 | "29": "Missouri", 205 | "30": "Montana", 206 | "31": "Nebraska", 207 | "32": "Nevada", 208 | "33": "New Hampshire", 209 | "34": "New Jersey", 210 | "35": "New Mexico", 211 | "36": "New York", 212 | "37": "North Carolina", 213 | "38": "North Dakota", 214 | "39": "Ohio", 215 | "40": "Oklahoma", 216 | "41": "Oregon", 217 | "42": "Pennsylvania", 218 | "44": "Rhode Island", 219 | "45": "South Carolina", 220 | "46": "South Dakota", 221 | "47": "Tennessee", 222 | "48": "Texas", 223 | "49": "Utah", 224 | "50": "Vermont", 225 | "51": "Virginia", 226 | "53": "Washington", 227 | "54": "West Virginia", 228 | "55": "Wisconsin", 229 | "56": "Wyoming" 230 | } 231 | } 232 | } 233 | } 234 | } -------------------------------------------------------------------------------- /R/jsonstat_methods.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | print.jsonstat <- function(x, ...){ 3 | cat("JSON-stat ", x$class, " object v.", x$version, sep = "") 4 | } 5 | 6 | #' @export 7 | print.jsonstat_dataset <- function(x, ...){ 8 | NextMethod(x) 9 | if(!is.null(x$label)) cat("\n", x$label, sep="") 10 | cat("\ndimensions: ") 11 | cat(paste(x$id, "(", x$size, ")", sep=""), sep = ", ") 12 | } 13 | 14 | #' @export 15 | dim.jsonstat_dataset <- function(x){ 16 | x$size 17 | } 18 | 19 | #' @export 20 | dimnames.jsonstat_dataset <- function(x){ 21 | dn <- lapply(x$dimension, 22 | FUN=function(X) { 23 | idx <- names(X$category$index) 24 | if(is.null(idx)) idx <- names(X$category$label) 25 | idx 26 | }) 27 | dn[x$id] 28 | } 29 | 30 | #' @export 31 | `dimnames<-.jsonstat_dataset` <- function (x, value){ 32 | stopifnot(all(names(value) == names(dimnames(x)))) 33 | for(i in seq_along(names(value))){ # i <- 2 34 | var_name <- names(value)[i] 35 | if(length(value[[i]]) == 1){ 36 | x$dimension[[var_name]]$category$index <- NULL 37 | value_exist <- value[[i]] %in% names(x$dimension[[var_name]]$category$label) 38 | if(value_exist) { 39 | lab <- x$dimension[[var_name]]$category$label[value[[i]]] 40 | } else { 41 | lab <- list("") 42 | names(lab) <- value[[i]] 43 | } 44 | x$dimension[[var_name]]$category$label <- lab 45 | } else { 46 | has_label <- !is.null(x$dimension[[var_name]]$category$label) 47 | has_index <- !is.null(x$dimension[[var_name]]$category$index) 48 | 49 | if(has_index){ 50 | idx <- as.list(0:(length(value[[i]])-1)) 51 | names(idx) <- value[[i]] 52 | x$dimension[[var_name]]$category$index <- idx 53 | } 54 | if(has_label){ 55 | lab_idx <- names(x$dimension[[var_name]]$category$label) %in% value[[i]] 56 | labs <- x$dimension[[var_name]]$category$label[lab_idx] 57 | new_labs <- !value[[i]] %in% names(x$dimension[[var_name]]$category$label) 58 | if(any(new_labs)) { 59 | extra_lab <- as.list(rep("", sum(new_labs))) 60 | names(extra_lab) <- value[[i]][new_labs] 61 | labs <- c(labs, extra_lab) 62 | } 63 | x$dimension[[var_name]]$category$label <- labs 64 | } 65 | } 66 | } 67 | x 68 | } 69 | 70 | #' @export 71 | as.array.jsonstat_dataset <- function(x, ...){ 72 | a <- array(data = x$value, dim = rev(x$size), dimnames = rev(dimnames(x)[x$id])) 73 | aperm(a, length(dim(a)):1) 74 | } 75 | 76 | #' @export 77 | `[.jsonstat_dataset` <- function(x, i, ..., drop = FALSE) 78 | { 79 | jsarray <- as.array(x) 80 | subs <- array_to_jsonstat_helper(jsarray[i, ..., drop = drop]) 81 | x$size <- subs$size 82 | x$value <- subs$value 83 | dimnames(x) <- subs$dimnames 84 | x 85 | } 86 | 87 | #' @export 88 | `[[.jsonstat_dataset` <- function(x, i, ...) 89 | { 90 | jsarray <- as.array(x) 91 | jsarray[i, ..., drop=FALSE] 92 | } 93 | 94 | array_to_jsonstat_helper <- function(jsa){ 95 | res <- list() 96 | res$size <- dim(jsa) 97 | res$value <- as.vector(aperm(jsa, length(dim(jsa)):1)) 98 | res$dimnames <- dimnames(jsa) 99 | res 100 | } 101 | 102 | #' @export 103 | `[<-.jsonstat_dataset` <- function(x, i, ..., value){ 104 | jsarray <- as.array(x) 105 | jsarray[1,1,3:5] <- 10:12 106 | jsarray[i, ...] <- value 107 | subs <- array_to_jsonstat_helper(jsarray) 108 | x$value <- subs$value 109 | x 110 | } 111 | 112 | #' @export 113 | as.data.frame.jsonstat_dataset <- function(x, row.names = NULL, optional = FALSE, ..., stringsAsFactors = FALSE){ 114 | df <- parse_dataset(dataset = x, naming = "id", use_factors = stringsAsFactors) 115 | if(!is.null(row.names)) rownames(df) <- row.names 116 | df 117 | } 118 | 119 | #' @export 120 | as.character.jsonstat <- function(x, ...){ 121 | as.character(as.json(x, ...)) 122 | } 123 | 124 | #' Convert to jsonlite json object 125 | #' 126 | #' @param x an object to coerce to a json object. 127 | #' @param ... additional arguments to be passed to or from methods. 128 | #' 129 | #' @details Currently only methods for \code{jsonstat} objects are implemented. 130 | #' 131 | #' @export 132 | as.json <- function(x, ...){ 133 | UseMethod("as.json") 134 | } 135 | 136 | #' @export 137 | as.json.jsonstat <- function(x, ...){ 138 | jsonlite::toJSON(unbox_jsonstat(x), na = "null", pretty = TRUE, digits = parse_digits(x$value), ...) 139 | } 140 | 141 | parse_digits <-function(x){ 142 | l <- strsplit(x = as.character(x), "\\.") 143 | has_decimals <- unlist(lapply(l, FUN=length)) > 1 144 | if(any(has_decimals)){ 145 | max(unlist(lapply(l[has_decimals], FUN=function(X) nchar(X[[2]])))) 146 | } else { 147 | 0 148 | } 149 | } 150 | 151 | unbox_jsonstat <- function(x){ 152 | x$version <- unbox(x$version) 153 | x$class <- unbox(x$class) 154 | if(!is.null(x$label)) x$label <- unbox(x$label) 155 | if(!is.null(x$href)) x$href <- unbox(x$href) 156 | if(!is.null(x$source)) x$source <- unbox(x$source) 157 | if(!is.null(x$updated)) x$updated <- unbox(x$updated) 158 | if(!is.null(x$status) && is.list(x$status)){ 159 | x$status <- lapply(x$status, unbox) 160 | } 161 | 162 | for(i in seq_along(x$dimension)){ 163 | x$dimension[[i]]$label <- unbox(x$dimension[[i]]$label) 164 | for(j in seq_along(x$dimension[[i]]$category$label)){ 165 | x$dimension[[i]]$category$label[[j]] <- unbox(x$dimension[[i]]$category$label[[j]]) 166 | } 167 | for(j in seq_along(x$dimension[[i]]$category$index)){ 168 | x$dimension[[i]]$category$index[[j]] <- unbox(x$dimension[[i]]$category$index[[j]]) 169 | } 170 | } 171 | x 172 | } 173 | 174 | #' @export 175 | as.vector.jsonstat_dataset <- function(x, mode = "any"){ 176 | as.vector(x$value, mode) 177 | } 178 | -------------------------------------------------------------------------------- /tests/testthat/test-jsonstat_methods.R: -------------------------------------------------------------------------------- 1 | context("jsonstat methods") 2 | 3 | ## TODO: Add assertions in all functions 4 | ## TODO: Subset dimensions (as jsonstat_dimensions object) 5 | ## TODO: Refactorize to handle collections correctly (as a list of jstat_datasets) objects 6 | 7 | test_that("print", { 8 | expect_output(print(as.jsonstat("dataset.json")), regexp = "JSON-stat dataset") 9 | expect_output(print(as.jsonstat("collection.json")), regexp = "JSON-stat collection") 10 | }) 11 | 12 | test_that("dim", { 13 | dim(as.jsonstat("oecd.json")) %>% 14 | expect_equal(c(1, 36, 12)) 15 | dim(as.jsonstat("canada.json")) %>% 16 | expect_equal(c(1, 1, 20, 2, 3)) 17 | dim(as.jsonstat("galicia.json")) %>% 18 | expect_equal(c(6, 22, 3, 2, 5, 1)) 19 | dim(as.jsonstat("collection.json")) %>% 20 | expect_null() 21 | }) 22 | 23 | 24 | test_that("dimnames", { 25 | test_dimnames_canada <- list(country = "CA") 26 | test_dimnames_canada$year <- "2012" 27 | test_dimnames_canada$age <- c("T", "4", "9", "14", "19", "24", "29", "34", "39", "44", "49", "54", "59", "64", "69", "74", "79", "84", "89", "older") 28 | test_dimnames_canada$concept <- c("POP", "PERCENT") 29 | test_dimnames_canada$sex <- c("T", "M", "F") 30 | 31 | dimnames(as.jsonstat("canada.json")) %>% 32 | expect_equal(test_dimnames_canada) 33 | }) 34 | 35 | 36 | test_that("is methods", { 37 | x <- as.jsonstat("oecd.json") 38 | expect_true(is.jsonstat(x)) 39 | expect_true(is.jsonstat_dataset(x)) 40 | expect_false(is.jsonstat_collection(x)) 41 | expect_false(is.jsonstat_dimension(x)) 42 | 43 | x <- as.jsonstat("oecd-canada-col.json") 44 | expect_true(is.jsonstat(x)) 45 | expect_false(is.jsonstat_dataset(x)) 46 | expect_true(is.jsonstat_collection(x)) 47 | expect_false(is.jsonstat_dimension(x)) 48 | }) 49 | 50 | test_that("extract", { 51 | x <- as.jsonstat("hierarchy.json") 52 | expect_identical(dim(x[2:3]), 2L) 53 | expect_identical(class(x[2:3]), class(x)) 54 | expect_identical(as.vector(x[[2:3]]), c(NA,NA)) 55 | expect_identical(class(x[[2:3]]), "array") 56 | 57 | x <- as.jsonstat("oecd.json") 58 | expect_identical(dim(x[1,5,1]), c(1L, 1L, 1L)) 59 | expect_identical(class(x[1,5,1]), class(x)) 60 | expect_identical(dim(x[1,2:5,1:3]), c(1L, 4L, 3L)) 61 | expect_identical(class(x[1,2:5,1:3]), class(x)) 62 | expect_identical(round(as.vector(x[[1,5,1]]), 4), 9.5434) 63 | expect_identical(class(x[[1,2:5,1:3]]), "array") 64 | }) 65 | 66 | test_that("as.array", { 67 | x <- as.jsonstat("hierarchy.json") 68 | expect_class(as.array(x), "array") 69 | expect_identical(as.vector(as.array(x)), rep(NA, 132)) 70 | 71 | x <- as.jsonstat("oecd.json") 72 | expect_class(as.array(x), "array") 73 | expect_identical(round(as.vector(as.array(x))[6:7],2), c(7.82, 5.34)) 74 | 75 | x <- as.jsonstat("us-gsp.json") 76 | expect_identical(as.vector(as.array(x = x[1,2,])), c(45600.0, 0.31, 0.7, 65143)) 77 | }) 78 | 79 | test_that("as.vector", { 80 | x <- as.jsonstat("us-gsp.json") 81 | a <- as.array(x) 82 | a <- aperm(a, perm = length(dim(a)):1) 83 | expect_identical(as.vector(a), as.vector(x)) 84 | }) 85 | 86 | test_that("as.array and as.data.frame", { 87 | x <- as.jsonstat("hierarchy.json") 88 | expect_class(as.data.frame(x), "data.frame") 89 | expect_identical(as.character(as.data.frame(x)$commodity[2:3]), c("1", "1.1")) 90 | expect_identical(as.data.frame(x)$value[2:3], rep(NA, 2)) 91 | 92 | x <- as.jsonstat("oecd.json") 93 | expect_class(as.data.frame(x), "data.frame") 94 | expect_identical(as.character(as.data.frame(x)$concept[7]), "UNR") 95 | expect_identical(as.character(as.data.frame(x)$area[10]), "AU") 96 | expect_identical(as.character(as.data.frame(x)$year[1]), "2003") 97 | expect_identical(round(as.data.frame(x)$value[12],3), 5.463) 98 | }) 99 | 100 | test_that("as.character", { 101 | x <- as.jsonstat("hierarchy.json") 102 | y <- as.jsonstat(as.character(x)) 103 | expect_identical(x, y) 104 | 105 | x <- as.jsonstat("oecd.json") 106 | y <- as.jsonstat(as.character(x)) 107 | expect_identical(x, y) 108 | 109 | if(FALSE){ 110 | x <- as.jsonstat("oecd-canada-col.json") 111 | y <- as.jsonstat(as.character(x)) 112 | expect_identical(x, y) 113 | } 114 | 115 | x <- as.jsonstat("canada.json") 116 | y <- as.jsonstat(as.character(x)) 117 | expect_identical(x, y) 118 | 119 | x <- as.jsonstat("galicia.json") 120 | y <- as.jsonstat(as.character(x)) 121 | expect_identical(x, y) 122 | 123 | x <- as.jsonstat("order.json") 124 | y <- as.jsonstat(as.character(x)) 125 | expect_identical(x, y) 126 | 127 | x <- as.jsonstat("order.json") 128 | y <- as.jsonstat(as.character(x)) 129 | expect_identical(x, y) 130 | 131 | x <- as.jsonstat("us-gsp.json") 132 | y <- as.jsonstat(as.character(x)) 133 | expect_identical(x, y) 134 | 135 | x <- as.jsonstat("us-unr.json") 136 | y <- as.jsonstat(as.character(x)) 137 | expect_identical(x, y) 138 | 139 | x <- as.jsonstat("us-labor.json") 140 | y <- as.jsonstat(as.character(x)) 141 | expect_identical(x, y) 142 | 143 | x <- as.jsonstat("collection_sample.json") 144 | y <- as.jsonstat(as.character(x)) 145 | expect_identical(x, y) 146 | 147 | js <- as.jsonstat("dataset2.json") 148 | ch <- paste(readLines("dataset2.json"), collapse = "\n") 149 | ch <- unlist(strsplit(ch, split = "\n")) 150 | jschar <- unlist(strsplit(as.character(x = js), split = "\n")) 151 | expect_identical(ch, jschar) 152 | 153 | x <- js <- as.jsonstat("oecd_tidy.json") 154 | ch <- paste(readLines("oecd_tidy.json"), collapse = "\n") 155 | ch <- unlist(strsplit(ch, split = "\n")) 156 | ch <- gsub("\t"," ", ch) 157 | jschar <- unlist(strsplit(as.character(js), split = "\n")) 158 | expect_identical(ch, jschar) 159 | 160 | if(FALSE){ 161 | x <- js <- as.jsonstat("oecd-canada-col.json") 162 | ch <- paste(readLines("oecd-canada-col.json"), collapse = "\n") 163 | ch <- unlist(strsplit(ch, split = "\n")) 164 | ch <- gsub("\t"," ", ch) 165 | jschar <- unlist(strsplit(as.character(js), split = "\n")) 166 | diff_idx <- which(jschar != ch)[i] 167 | ch[diff_idx];jschar[diff_idx] 168 | diff_idx 169 | i <- i + 1 170 | expect_identical(ch, jschar) 171 | } 172 | 173 | }) 174 | 175 | test_that("set values", { 176 | x <- as.jsonstat("oecd.json") 177 | expect_silent(x[1,1,1] <- 100.1) 178 | expect_identical(as.vector(x[[1,1,1]]), 100.1) 179 | expect_silent(x[1,1,3:5] <- 10:12) 180 | expect_identical(as.vector(x[[1,1,3:5]]), as.numeric(10:12)) 181 | }) 182 | 183 | test_that("identified bugs", { 184 | x <- as.jsonstat("oecd.json") 185 | expect_silent(as.data.frame(x[1,1,1])) 186 | }) 187 | -------------------------------------------------------------------------------- /tests/testthat/hierarchy.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "dataset", 4 | "href" : "https://json-stat.org/samples/hierarchy.json", 5 | "label" : "Demo of hierarchical dimension", 6 | "source" : "16th Series CPI Commodity Classification (http://www.abs.gov.au/AUSSTATS/abs@.nsf/DetailsPage/6401.0.55.0042011)", 7 | "updated" : "2011-07-01", 8 | "value" : { "0" : null }, 9 | "id" : ["commodity"], 10 | "size" : [132], 11 | "dimension" : { 12 | "commodity" : { 13 | "label" : "CPI commodity", 14 | "category" : { 15 | "index" : [ "T", "1", "1.1", "1.1.1", "1.1.2", "1.1.3", "1.1.4", "1.2", "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.2.5", "1.2.6", "1.3", "1.3.1", "1.3.2", "1.3.3", "1.4", "1.4.1", "1.4.2", "1.5", "1.5.1", "1.5.2", "1.5.3", "1.5.4", "1.5.5", "1.5.6", "1.6", "1.6.1", "1.6.2", "1.7", "1.7.1", "1.7.2", "2", "2.1", "2.1.1", "2.1.2", "2.1.3", "2.2", "2.2.1", "3", "3.1", "3.1.1", "3.1.2", "3.1.3", "3.2", "3.2.1", "3.2.2", "3.2.3", "3.3", "3.3.1", "3.3.2", "4", "4.1", "4.1.1", "4.2", "4.2.1", "4.3", "4.3.1", "4.3.2", "4.4", "4.4.1", "4.4.2", "4.4.3", "5", "5.1", "5.1.1", "5.1.2", "5.2", "5.2.1", "5.3", "5.3.1", "5.3.2", "5.3.3", "5.3.4", "5.4", "5.4.1", "5.4.2", "5.4.3", "5.5", "5.5.1", "5.5.2", "5.5.3", "6", "6.1", "6.1.1", "6.1.2", "6.2", "6.2.1", "6.2.2", "7", "7.1", "7.1.1", "7.1.2", "7.1.3", "7.1.4", "7.1.5", "7.2", "7.2.1", "8", "8.1", "8.1.1", "8.1.2", "9", "9.1", "9.1.1", "9.1.2", "9.2", "9.2.1", "9.2.2", "9.3", "9.3.1", "9.3.2", "9.4", "9.4.1", "9.4.2", "9.4.3", "9.4.4", "9.4.5", "9.4.6", "10", "10.1", "10.1.1", "10.1.2", "10.1.3", "11", "11.1", "11.1.1", "11.2", "11.2.1", "11.2.2" ], 16 | "label" : { 17 | "T" : "Total", 18 | "1" : "Food and non-alcoholic beverages", 19 | "1.1" : "Bread and cereal products", 20 | "1.1.1" : "Bread", 21 | "1.1.2" : "Cakes and biscuits", 22 | "1.1.3" : "Breakfast cereals", 23 | "1.1.4" : "Other cereal products", 24 | "1.2" : "Meat and seafoods", 25 | "1.2.1" : "Beef and veal", 26 | "1.2.2" : "Pork", 27 | "1.2.3" : "Lamb and goat", 28 | "1.2.4" : "Poultry", 29 | "1.2.5" : "Other meats", 30 | "1.2.6" : "Fish and other seafood", 31 | "1.3" : "Dairy and related products", 32 | "1.3.1" : "Milk", 33 | "1.3.2" : "Cheese", 34 | "1.3.3" : "Ice cream and other dairy products", 35 | "1.4" : "Fruit and vegetables", 36 | "1.4.1" : "Fruit", 37 | "1.4.2" : "Vegetables", 38 | "1.5" : "Food products n.e.c.", 39 | "1.5.1" : "Eggs", 40 | "1.5.2" : "Jams, honey and spreads", 41 | "1.5.3" : "Food additives and condiments", 42 | "1.5.4" : "Oils and fats", 43 | "1.5.5" : "Snacks and confectionery", 44 | "1.5.6" : "Other food products n.e.c.", 45 | "1.6" : "Non-alcoholic beverages", 46 | "1.6.1" : "Coffee, tea and cocoa", 47 | "1.6.2" : "Waters, soft drinks and juices", 48 | "1.7" : "Meals out and take away foods", 49 | "1.7.1" : "Restaurant meals", 50 | "1.7.2" : "Take away and fast foods", 51 | "2" : "Alcohol and tobacco", 52 | "2.1" : "Alcoholic beverages", 53 | "2.1.1" : "Spirits", 54 | "2.1.2" : "Wine", 55 | "2.1.3" : "Beer", 56 | "2.2" : "Tobacco", 57 | "2.2.1" : "Tobacco", 58 | "3" : "Clothing and footwear", 59 | "3.1" : "Garments", 60 | "3.1.1" : "Garments for men", 61 | "3.1.2" : "Garments for women", 62 | "3.1.3" : "Garments for infants and children", 63 | "3.2" : "Footwear", 64 | "3.2.1" : "Footwear for men", 65 | "3.2.2" : "Footwear for women", 66 | "3.2.3" : "Footwear for infants and children", 67 | "3.3" : "Accessories and clothing services", 68 | "3.3.1" : "Accessories", 69 | "3.3.2" : "Cleaning, repair and hire of clothing and footwear", 70 | "4" : "Housing", 71 | "4.1" : "Rents", 72 | "4.1.1" : "Rents", 73 | "4.2" : "New dwelling purchase by owner-occupiers", 74 | "4.2.1" : "New dwelling purchase by owner-occupiers", 75 | "4.3" : "Other housing", 76 | "4.3.1" : "Maintenance and repair of the dwelling", 77 | "4.3.2" : "Property rates and charges", 78 | "4.4" : "Utilities", 79 | "4.4.1" : "Water and sewerage", 80 | "4.4.2" : "Electricity", 81 | "4.4.3" : "Gas and other household fuels", 82 | "5" : "Furnishings, household equipment and services", 83 | "5.1" : "Furniture and furnishings", 84 | "5.1.1" : "Furniture", 85 | "5.1.2" : "Carpets and other floor coverings", 86 | "5.2" : "Household textiles", 87 | "5.2.1" : "Household textiles", 88 | "5.3" : "Household appliances, utensils and tools", 89 | "5.3.1" : "Major household appliances", 90 | "5.3.2" : "Small electric household appliances ", 91 | "5.3.3" : "Glassware, tableware and household utensils", 92 | "5.3.4" : "Tools and equipment for house and garden", 93 | "5.4" : "Non-durable household products", 94 | "5.4.1" : "Cleaning and maintenance products", 95 | "5.4.2" : "Personal care products", 96 | "5.4.3" : "Other non-durable household products", 97 | "5.5" : "Domestic and household services", 98 | "5.5.1" : "Child care", 99 | "5.5.2" : "Hairdressing and personal grooming services", 100 | "5.5.3" : "Other household services", 101 | "6" : "Health", 102 | "6.1" : "Medical products, appliances and equipment", 103 | "6.1.1" : "Pharmaceutical products", 104 | "6.1.2" : "Therapeutic appliances and equipment", 105 | "6.2" : "Medical, dental and hospital services", 106 | "6.2.1" : "Medical and hospital services", 107 | "6.2.2" : "Dental services", 108 | "7" : "Transport", 109 | "7.1" : "Private motoring", 110 | "7.1.1" : "Motor vehicles", 111 | "7.1.2" : "Spare parts and accessories for motor vehicles", 112 | "7.1.3" : "Automotive fuel", 113 | "7.1.4" : "Maintenance and repair of motor vehicles", 114 | "7.1.5" : "Other services in respect of motor vehicles", 115 | "7.2" : "Urban transport fares", 116 | "7.2.1" : "Urban transport fares", 117 | "8" : "Communication", 118 | "8.1" : "Communication", 119 | "8.1.1" : "Postal services", 120 | "8.1.2" : "Telecommunication equipment and services", 121 | "9" : "Recreation and culture", 122 | "9.1" : "Audio, visual and computing equipment and services", 123 | "9.1.1" : "Audio, visual and computing equipment", 124 | "9.1.2" : "Audio, visual and computing media and services", 125 | "9.2" : "Newspapers, books and stationery", 126 | "9.2.1" : "Books", 127 | "9.2.2" : "Newspapers, magazines and stationery", 128 | "9.3" : "Holiday travel and accommodation", 129 | "9.3.1" : "Domestic holiday travel and accommodation", 130 | "9.3.2" : "International holiday travel and accommodation", 131 | "9.4" : "Other recreation, sport and culture", 132 | "9.4.1" : "Equipment for sports, camping and open-air recreation", 133 | "9.4.2" : "Games, toys and hobbies", 134 | "9.4.3" : "Pets and related products", 135 | "9.4.4" : "Veterinary and other services for pets", 136 | "9.4.5" : "Sports participation", 137 | "9.4.6" : "Other recreational, sporting and cultural services", 138 | "10" : "Education", 139 | "10.1" : "Education", 140 | "10.1.1" : "Preschool and primary education", 141 | "10.1.2" : "Secondary education", 142 | "10.1.3" : "Tertiary education", 143 | "11" : "Insurance and financial services", 144 | "11.1" : "Insurance", 145 | "11.1.1" : "Insurance", 146 | "11.2" : "Financial services", 147 | "11.2.1" : "Deposit and loan facilities (direct charges)", 148 | "11.2.2" : "Other financial services" 149 | }, 150 | "child" : { 151 | "T" : [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11" ], 152 | "1" : [ "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7" ], 153 | "2" : [ "2.1", "2.2" ], 154 | "3" : [ "3.1", "3.2", "3.3" ], 155 | "4" : [ "4.1", "4.2", "4.3", "4.4" ], 156 | "5" : [ "5.1", "5.2", "5.3", "5.4", "5.5" ], 157 | "6" : [ "6.1", "6.2" ], 158 | "7" : [ "7.1", "7.2" ], 159 | "8" : [ "8.1" ], 160 | "9" : [ "9.1", "9.2", "9.3", "9.4" ], 161 | "10" : [ "10.1" ], 162 | "11" : [ "11.1", "11.2" ], 163 | "1.1" : [ "1.1.1", "1.1.2", "1.1.3", "1.1.4" ], 164 | "1.2" : [ "1.2.1", "1.2.2", "1.2.3", "1.2.4", "1.2.5", "1.2.6" ], 165 | "1.3" : [ "1.3.1", "1.3.2", "1.3.3" ], 166 | "1.4" : [ "1.4.1", "1.4.2" ], 167 | "1.5" : [ "1.5.1", "1.5.2", "1.5.3", "1.5.4", "1.5.5", "1.5.6"], 168 | "1.6" : [ "1.6.1", "1.6.2" ], 169 | "1.7" : [ "1.7.1", "1.7.2" ], 170 | "2.1" : [ "2.1.1", "2.1.2", "2.1.3" ], 171 | "2.2" : [ "2.2.1" ], 172 | "3.1" : [ "3.1.1", "3.1.2", "3.1.3" ], 173 | "3.2" : [ "3.2.1", "3.2.2", "3.2.3" ], 174 | "3.3" : [ "3.3.1", "3.3.2" ], 175 | "4.1" : [ "4.1.1" ], 176 | "4.2": [ "4.2.1" ], 177 | "4.3" : [ "4.3.1", "4.3.2" ], 178 | "4.4" : [ "4.4.1", "4.4.2", "4.4.3" ], 179 | "5.1" : [ "5.1.1", "5.1.2" ], 180 | "5.2" : [ "5.2.1" ], 181 | "5.3" : [ "5.3.1", "5.3.2", "5.3.3", "5.3.4" ], 182 | "5.4" : [ "5.4.1", "5.4.2", "5.4.3" ], 183 | "5.5" : [ "5.5.1", "5.5.2", "5.5.3" ], 184 | "6.1" : [ "6.1.1", "6.1.2" ], 185 | "6.2" : [ "6.2.1", "6.2.2" ], 186 | "7.1" : [ "7.1.1", "7.1.2", "7.1.3", "7.1.4", "7.1.5" ], 187 | "7.2" : [ "7.2.1" ], 188 | "8.1" : [ "8.1.1", "8.1.2" ], 189 | "9.1" : [ "9.1.1", "9.1.2" ], 190 | "9.2" : [ "9.2.1", "9.2.2" ], 191 | "9.3" : [ "9.3.1", "9.3.2" ], 192 | "9.4" : [ "9.4.1", "9.4.2", "9.4.3", "9.4.4", "9.4.5", "9.4.6" ], 193 | "10.1" : [ "10.1.1", "10.1.2", "10.1.3" ], 194 | "11.1" : [ "11.1.1" ], 195 | "11.2" : [ "11.2.1", "11.2.2" ] 196 | } 197 | } 198 | } 199 | } 200 | } -------------------------------------------------------------------------------- /tests/testthat/oecd_tidy.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "class": "dataset", 4 | "href": "https://json-stat.org/samples/oecd.json", 5 | "label": "Unemployment rate in the OECD countries 2003-2014", 6 | "note": ["Most of the data in this dataset are taken from the individual contributions of national correspondents appointed by the OECD Secretariat with the approval of the authorities of Member countries. Consequently, these data have not necessarily been harmonised at international level."], 7 | "source": "Economic Outlook No 92 - December 2012 - OECD Annual Projections", 8 | "updated": "2012-11-27", 9 | "value": [5.943826289, 5.39663128, 5.044790587, 4.789362794, 4.379649386, 4.249093453, 5.592226603, 5.230660289, 5.099422942, 5.224336088, 5.50415003, 5.462866231, 4.278559338, 4.939707755, 5.152160612, 4.727182858, 4.399730726, 3.813933625, 4.776912506, 4.391591645, 4.143587245, 4.351345785, 4.695491708, 4.745323313, 8.158333333, 8.4, 8.483333333, 8.266666667, 7.466666667, 7.016666667, 7.891892855, 8.283171959, 7.175138783, 7.381153404, 7.689552898, 7.735442636, 7.594616751, 7.167833951, 6.748691501, 6.307841105, 6.049842626, 6.146014664, 8.284689299, 7.988900419, 7.453609598, 7.32358421, 7.169741525, 6.88122705, 9.5433848, 10.00149582, 9.224422554, 7.773166282, 7.150623348, 7.787221805, 10.80236438, 8.121579077, 7.104778251, 6.477468723, 6.78101031, 6.780198936, 7.818066527, 8.323638425, 7.922330988, 7.142271671, 5.316363283, 4.391669598, 6.675050668, 7.273107122, 6.723482523, 6.936394665, 7.242148075, 7.135151601, 5.344516646, 5.516904324, 4.793715416, 3.868296418, 3.669496447, 3.326692683, 5.821647379, 7.191696186, 7.313112408, 7.544640558, 7.357364231, 7.255659852, 10.03010116, 9.661753538, 7.899232972, 5.905173373, 4.659913473, 5.601684952, 13.87805579, 16.83438817, 12.4576855, 9.873121257, 9.116309666, 8.74566981, 9.017860131, 8.80435787, 8.368797468, 7.702632855, 6.850344695, 6.368216471, 8.269856093, 8.381534292, 7.774845319, 7.722836877, 7.962718148, 7.757742455, 8.503978378, 8.8650811, 8.882978134, 8.835277292, 8.009145174, 7.384897537, 9.129199553, 9.315864403, 9.202432489, 9.877166456, 10.66140443, 10.91985917, 9.134738857, 9.829230121, 10.69442137, 9.694756306, 8.310233377, 7.188163108, 7.429105355, 6.757338631, 5.752587233, 5.28775372, 5.524081118, 5.565600014, 9.712526535, 10.49281197, 9.849833119, 8.890878396, 8.276300402, 7.653084476, 9.460314273, 12.53058153, 17.65238747, 23.5737508, 26.6534591, 27.2364419, 5.860132523, 6.096400087, 7.185491402, 7.451740837, 7.35706148, 7.851089777, 10.0153875, 11.14448405, 10.92071597, 11.12538821, 11.09958634, 10.76358386, 3.352836045, 3.06335905, 2.590345651, 2.878830234, 2.301867378, 2.990597714, 7.241470693, 7.55861225, 7.058807671, 6.138731401, 5.393148124, 5.128315309, 4.739670964, 4.539966682, 4.341850838, 4.415526325, 4.571302023, 6.024123088, 11.81229736, 13.62078809, 14.51224844, 14.79227286, 14.73886731, 14.61076214, 13.28016732, 12.85704871, 11.29834866, 10.47596715, 9.147672881, 7.728344307, 9.476560711, 8.33683595, 7.110513831, 6.8731402, 7.359377644, 6.93094611, 8.444973801, 7.996760207, 7.708360512, 6.777043598, 6.110290905, 6.774113796, 7.800833899, 8.41234985, 8.438703909, 10.55546863, 11.42167502, 11.7584873, 5.25125, 4.717099486, 4.424423923, 4.129376275, 3.84841253, 3.979750388, 5.068375853, 5.058985674, 4.592622773, 4.399496241, 4.355894653, 4.286733019, 3.562065618, 3.67219364, 3.734708533, 3.450431799, 3.233335111, 3.15974989, 3.643064158, 3.715763348, 3.405129308, 3.378067785, 3.618601827, 3.397535556, 3.304883869, 3.710506994, 4.099797561, 4.242014975, 4.182611437, 4.14500326, 5.431987487, 5.778771292, 5.627283477, 6.078760003, 6.589474092, 6.658818611, 2.998805894, 3.695332444, 3.540173119, 3.550553518, 3.672170595, 3.949416134, 5.43621902, 5.373117407, 5.240905522, 5.036393758, 4.990182757, 4.897580596, 3.975713818, 4.894207123, 5.113659881, 4.20994586, 3.475695941, 3.018534226, 3.68444758, 4.383579198, 4.343866431, 5.163411369, 5.801548283, 6.10348765, 4.76074516, 4.018968583, 3.807106599, 3.840522581, 3.655294639, 4.160280272, 6.146341463, 6.537348623, 6.509125435, 6.938443309, 6.568824155, 6.048820957, 4.04172726, 4.186831741, 4.382939676, 3.392420144, 2.498729296, 2.565344859, 3.107969091, 3.521797592, 3.212318473, 3.098584692, 3.098584692, 3.003021166, 19.61702787, 18.97466246, 17.74593227, 13.84039072, 9.601554043, 7.117494731, 8.166610723, 9.622661542, 9.648757987, 10.05073744, 10.49463234, 10.66450371, 6.276549712, 6.666642728, 7.597516675, 7.637987286, 7.99012509, 7.607584033, 9.484363464, 10.81324061, 12.7097409, 15.52457602, 16.93137173, 16.62982306, 17.55389647, 18.22108629, 16.25634386, 13.3725907, 11.14262294, 9.507520125, 12.02516939, 14.37913326, 13.54138898, 13.69591839, 13.5763623, 12.97187212, 6.682102697, 6.291982582, 6.516689478, 5.945157013, 4.816202781, 4.368899066, 5.856004508, 7.240345922, 8.164977774, 8.529917685, 9.708595873, 9.847243093, 11.03816292, 10.54622939, 9.156961086, 8.511101588, 8.264570818, 11.33829871, 18.01195661, 20.06321219, 21.63712759, 25.04773498, 26.89014696, 26.78073067, 6.56574156, 7.373480411, 7.652096974, 7.053667613, 6.127066505, 6.183935584, 8.305635992, 8.372715009, 7.504247076, 7.651519753, 7.912693788, 7.604124855, 4.033356027, 4.31699694, 4.329724566, 3.941659077, 3.57509152, 3.341272685, 4.257833072, 4.44955058, 3.949110999, 3.863659425, 4.109877511, 3.999499419, 10.82310834, 10.58802629, 10.40296232, 10.01247258, 10.06182773, 10.74264555, 13.74762357, 11.65601928, 9.605142332, 9.014001387, 9.320782097, 8.651402638, 5.019884066, 4.768990278, 4.852538715, 5.450636437, 5.355104552, 5.708223236, 7.62507775, 7.861627732, 8.078635307, 8.027613742, 8.275155581, 8.036560522, 5.986539203, 5.523039996, 5.076780521, 4.617465075, 4.619105436, 5.800444743, 9.275245924, 9.627692959, 8.94612643, 8.091574662, 7.810715126, 7.514930043, 8.68886389, 8.942669403, 8.941482912, 8.233837469, 7.409607055, 7.436710115, 9.371745367, 9.891824566, 9.978460373, 11.11907575, 11.9135905, 11.99849464, 6.971079892, 6.859814025, 6.629153129, 6.100565063, 5.656171098, 5.982685271, 8.157564657, 8.320563893, 7.953121271, 7.970392182, 8.15379125, 8.004598637], 10 | "status": { 11 | "10": "e", 12 | "11": "e", 13 | "22": "e", 14 | "23": "e", 15 | "34": "e", 16 | "35": "e", 17 | "46": "e", 18 | "47": "e", 19 | "58": "e", 20 | "59": "e", 21 | "70": "e", 22 | "71": "e", 23 | "82": "e", 24 | "83": "e", 25 | "94": "e", 26 | "95": "e", 27 | "106": "e", 28 | "107": "e", 29 | "118": "e", 30 | "119": "e", 31 | "130": "e", 32 | "131": "e", 33 | "142": "e", 34 | "143": "e", 35 | "154": "e", 36 | "155": "e", 37 | "166": "e", 38 | "167": "e", 39 | "178": "e", 40 | "179": "e", 41 | "190": "e", 42 | "191": "e", 43 | "202": "e", 44 | "203": "e", 45 | "214": "e", 46 | "215": "e", 47 | "226": "e", 48 | "227": "e", 49 | "238": "e", 50 | "239": "e", 51 | "250": "e", 52 | "251": "e", 53 | "262": "e", 54 | "263": "e", 55 | "274": "e", 56 | "275": "e", 57 | "286": "e", 58 | "287": "e", 59 | "298": "e", 60 | "299": "e", 61 | "310": "e", 62 | "311": "e", 63 | "322": "e", 64 | "323": "e", 65 | "334": "e", 66 | "335": "e", 67 | "346": "e", 68 | "347": "e", 69 | "358": "e", 70 | "359": "e", 71 | "370": "e", 72 | "371": "e", 73 | "382": "e", 74 | "383": "e", 75 | "394": "e", 76 | "395": "e", 77 | "406": "e", 78 | "407": "e", 79 | "418": "e", 80 | "419": "e", 81 | "430": "e", 82 | "431": "e" 83 | }, 84 | "id": ["concept", "area", "year"], 85 | "size": [1, 36, 12], 86 | "role": { 87 | "time": ["year"], 88 | "geo": ["area"], 89 | "metric": ["concept"] 90 | }, 91 | "dimension": { 92 | "concept": { 93 | "label": "indicator", 94 | "category": { 95 | "label": { 96 | "UNR": "unemployment rate" 97 | } 98 | } 99 | }, 100 | "year": { 101 | "label": "2003-2014", 102 | "category": { 103 | "index": { 104 | "2003": 0, 105 | "2004": 1, 106 | "2005": 2, 107 | "2006": 3, 108 | "2007": 4, 109 | "2008": 5, 110 | "2009": 6, 111 | "2010": 7, 112 | "2011": 8, 113 | "2012": 9, 114 | "2013": 10, 115 | "2014": 11 116 | } 117 | } 118 | }, 119 | "area": { 120 | "label": "OECD countries, EU15 and total", 121 | "note": ["Except where otherwise indicated, data refer to the actual territory of the country considered."], 122 | "category": { 123 | "index": { 124 | "AU": 0, 125 | "AT": 1, 126 | "BE": 2, 127 | "CA": 3, 128 | "CL": 4, 129 | "CZ": 5, 130 | "DK": 6, 131 | "EE": 7, 132 | "FI": 8, 133 | "FR": 9, 134 | "DE": 10, 135 | "GR": 11, 136 | "HU": 12, 137 | "IS": 13, 138 | "IE": 14, 139 | "IL": 15, 140 | "IT": 16, 141 | "JP": 17, 142 | "KR": 18, 143 | "LU": 19, 144 | "MX": 20, 145 | "NL": 21, 146 | "NZ": 22, 147 | "NO": 23, 148 | "PL": 24, 149 | "PT": 25, 150 | "SK": 26, 151 | "SI": 27, 152 | "ES": 28, 153 | "SE": 29, 154 | "CH": 30, 155 | "TR": 31, 156 | "UK": 32, 157 | "US": 33, 158 | "EU15": 34, 159 | "OECD": 35 160 | }, 161 | "label": { 162 | "AU": "Australia", 163 | "AT": "Austria", 164 | "BE": "Belgium", 165 | "CA": "Canada", 166 | "CL": "Chile", 167 | "CZ": "Czech Republic", 168 | "DK": "Denmark", 169 | "EE": "Estonia", 170 | "FI": "Finland", 171 | "FR": "France", 172 | "DE": "Germany", 173 | "GR": "Greece", 174 | "HU": "Hungary", 175 | "IS": "Iceland", 176 | "IE": "Ireland", 177 | "IL": "Israel", 178 | "IT": "Italy", 179 | "JP": "Japan", 180 | "KR": "Korea", 181 | "LU": "Luxembourg", 182 | "MX": "Mexico", 183 | "NL": "Netherlands", 184 | "NZ": "New Zealand", 185 | "NO": "Norway", 186 | "PL": "Poland", 187 | "PT": "Portugal", 188 | "SK": "Slovak Republic", 189 | "SI": "Slovenia", 190 | "ES": "Spain", 191 | "SE": "Sweden", 192 | "CH": "Switzerland", 193 | "TR": "Turkey", 194 | "UK": "United Kingdom", 195 | "US": "United States", 196 | "EU15": "Euro area (15 countries)", 197 | "OECD": "total" 198 | }, 199 | "note": { 200 | "DE": ["Germany (code DE) was created 3 October 1990 by the accession of the Democratic Republic of Germany (code DDR) to the then Federal Republic of Germany (code DEW)."] 201 | }, 202 | "child": { 203 | "EU15": ["AT", "BE", "DE", "DK", "ES", "FI", "FR", "GR", "IE", "IT", "LU", "NL", "PT", "SE", "UK"], 204 | "OECD": ["EU15", "AU", "CA", "CL", "CZ", "DK", "EE", "HU", "IS", "IL", "JP", "KR", "MX", "NO", "NZ", "PL", "SK", "SI", "CH", "TR", "US"] 205 | } 206 | } 207 | } 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /R/rjstat.R: -------------------------------------------------------------------------------- 1 | #' Read and write JSON-stat data sets 2 | #' 3 | #' \href{https://json-stat.org}{JSON-stat} is a JSON format for data 4 | #' dissemination. The \pkg{rjstat} package converts data frames to and from this 5 | #' format. The extensive metadata features of JSON-stat are not supported. 6 | #' 7 | #' @docType package 8 | #' @name rjstat 9 | #' @aliases rjstat-package 10 | #' @import jsonlite 11 | #' @import checkmate 12 | NULL 13 | 14 | #' Convert JSON-stat format to data frame(s) 15 | #' 16 | #' This function takes a JSON-stat format response and returns a data frame or a 17 | #' list of data frames, with columns for each dimension and one \code{value} 18 | #' column. 19 | #' 20 | #' @param x JSON-stat format response, or path or URL to such a response 21 | #' @param naming whether to use (longer) \code{label}s or (shorter) \code{id}s 22 | #' @param use_factors whether dimension categories should be factors or 23 | #' character objects 24 | #' @param silent suppress warnings 25 | #' 26 | #' @return For responses with class \code{dataset}: A data frame. For responses 27 | #' with class \code{collection}: An unnamed list of one or more lists or data 28 | #' frames. For responses with class \code{bundle}: A named list of one or more 29 | #' data frames. 30 | #' 31 | #' @export 32 | #' @examples 33 | #' \dontrun{ 34 | #' oecd.canada.url <- "https://json-stat.org/samples/oecd-canada.json" 35 | #' results <- fromJSONstat(oecd.canada.url) 36 | #' names(results) 37 | #' } 38 | fromJSONstat <- function(x, naming = "label", use_factors = FALSE, 39 | silent = FALSE) { 40 | assert_choice(naming, c("label", "id")) 41 | assert_flag(use_factors) 42 | assert_flag(silent) 43 | 44 | x <- fromJSON(x, simplifyDataFrame = FALSE) 45 | 46 | parse_list(x, naming, use_factors, silent) 47 | } 48 | 49 | parse_list <- function(x, naming, use_factors, silent) { 50 | assert_list(x, min.len = 1) 51 | if (identical(x$class, "dataset")) { 52 | parse_dataset_class(x, naming, use_factors, silent) 53 | } else if (identical(x$class, "dimension")) { 54 | parse_dimension_class(x, naming, use_factors, silent) 55 | } else if (identical(x$class, "collection")) { 56 | parse_collection_class(x, naming, use_factors, silent) 57 | } else { 58 | parse_bundle_class(x, naming, use_factors) 59 | } 60 | } 61 | 62 | parse_dataset_class <- function(x, naming, use_factors, silent) { 63 | if (is.null(x$value)) { 64 | if (!silent) { 65 | warning("no values in dataset, returning unparsed list", 66 | call. = FALSE) 67 | } 68 | x 69 | } else { 70 | parse_dataset(x, naming, use_factors) 71 | } 72 | } 73 | 74 | parse_dimension_class <- function(x, naming, use_factors, silent) { 75 | if (!silent) { 76 | warning("dimension responses not implemented, returning unparsed list", 77 | call. = FALSE) 78 | } 79 | x 80 | } 81 | 82 | parse_collection_class <- function(x, naming, use_factors, silent) { 83 | if (is.null(x$link$item)) { 84 | if (!silent) { 85 | warning("no link items in collection, returning unparsed list", 86 | call. = FALSE) 87 | } 88 | x 89 | } else { 90 | lapply(x$link$item, parse_list, naming, use_factors, silent) 91 | } 92 | } 93 | 94 | parse_bundle_class <- function(x, naming, use_factors) { 95 | datasets <- lapply(x, parse_dataset, naming, use_factors) 96 | 97 | if (identical(naming, "label")) { 98 | names(datasets) <- get_labels(x) 99 | } 100 | 101 | datasets 102 | } 103 | 104 | parse_dataset <- function(dataset, naming, use_factors) { 105 | assert_list(dataset, min.len = 2) 106 | 107 | sizes <- as.integer(dataset$size) 108 | if (length(sizes) < 1) { 109 | sizes <- as.integer(dataset$dimension$size) 110 | } 111 | assert_integer(sizes, lower = 1, any.missing = FALSE, min.len = 1) 112 | 113 | n_rows <- prod(sizes) 114 | n_dims <- length(sizes) 115 | 116 | dimension_ids <- as.character(dataset$id) 117 | if (length(dimension_ids) < 1) { 118 | dimension_ids <- as.character(dataset$dimension$id) 119 | } 120 | assert_character(dimension_ids, min.chars = 1, any.missing = FALSE, 121 | len = n_dims, unique = TRUE) 122 | 123 | dimensions <- dataset$dimension 124 | assert_list(dimensions, min.len = n_dims) 125 | assert_subset(dimension_ids, names(dimensions)) 126 | dimensions <- dimensions[dimension_ids] 127 | 128 | dimension_categories <- lapply(dimensions, parse_dimension, naming) 129 | assert_list(dimension_categories, types = "character", len = n_dims, 130 | names = "unique") 131 | 132 | s <- vapply(dimension_categories, length, integer(1)) 133 | assert_set_equal(sizes, s, ordered = TRUE) 134 | 135 | dataframe <- rev(expand.grid(rev(dimension_categories), 136 | stringsAsFactors = use_factors)) 137 | if (identical(naming, "label")) { 138 | names(dataframe) <- get_labels(dimensions) 139 | } 140 | assert_data_frame(dataframe, types = c("character", "factor"), 141 | any.missing = FALSE, nrows = n_rows, ncols = n_dims) 142 | 143 | values <- dataset$value 144 | if (is.list(values)) { 145 | values <- unlist(values) 146 | v <- rep(NA, n_rows) 147 | i <- as.integer(names(values)) + 1L 148 | assert_integer(i, lower = 1, upper = n_rows, any.missing = FALSE, 149 | max.len = n_rows, unique = TRUE) 150 | v[i] <- values 151 | values <- v 152 | } 153 | assert_atomic(values, len = n_rows) 154 | 155 | dataframe <- cbind(dataframe, value = values, stringsAsFactors = FALSE) 156 | assert_data_frame(dataframe, types = "atomic", nrows = n_rows, 157 | ncols = n_dims + 1) 158 | 159 | dataframe 160 | } 161 | 162 | parse_dimension <- function(dimension, naming) { 163 | assert_list(dimension, min.len = 1) 164 | 165 | categories <- dimension$category 166 | assert_list(categories, min.len = 1) 167 | 168 | index <- categories$index 169 | labels <- categories$label 170 | 171 | if (is.null(index)) { 172 | parse_no_index(labels, naming) 173 | } else if (is.list(index)) { 174 | parse_object_index(index, labels, naming) 175 | } else { 176 | parse_array_index(index, labels, naming) 177 | } 178 | } 179 | 180 | parse_no_index <- function(labels, naming) { 181 | assert_list(labels, len = 1) 182 | if (identical(naming, "label")) { 183 | categories <- as.character(unlist(labels)) 184 | } else { 185 | categories <- names(labels) 186 | } 187 | assert_character(categories, min.chars = 1, any.missing = FALSE, len = 1) 188 | categories 189 | } 190 | 191 | parse_object_index <- function(index, labels, naming) { 192 | categories <- names(sort(unlist(index))) 193 | if (identical(naming, "label") && setequal(names(labels), categories)) { 194 | categories <- as.character(unlist(labels[categories])) 195 | } 196 | assert_character(categories, min.chars = 1, any.missing = FALSE, 197 | min.len = 1) 198 | categories 199 | } 200 | 201 | parse_array_index <- function(index, labels, naming) { 202 | categories <- as.character(index) 203 | if (identical(naming, "label") && setequal(names(labels), categories)) { 204 | categories <- as.character(unlist(labels[categories])) 205 | } 206 | assert_character(categories, min.chars = 1, any.missing = FALSE, 207 | min.len = 1) 208 | categories 209 | } 210 | 211 | get_labels <- function(x) { 212 | labels <- lapply(x, getElement, "label") 213 | i <- vapply(labels, is.null, logical(1)) 214 | labels[i] <- names(labels)[i] 215 | as.character(labels) 216 | } 217 | 218 | #' Convert data frame(s) to JSON-stat format 219 | #' 220 | #' This function takes a data frame or list of data frames and returns 221 | #' a string representation in JSON-stat format. The input data frame(s) 222 | #' must be in maximally long tidy format: with only one \code{value} 223 | #' column and all other columns representing dimensions. 224 | #' 225 | #' @param x a data frame or list of data frames 226 | #' @param value name of value column 227 | #' @param ... arguments passed on to \code{\link[jsonlite]{toJSON}} 228 | #' 229 | #' @return For a data frame: A JSON-stat format response with class 230 | #' \code{dataset}. For a list of data frames: A JSON-stat format response with 231 | #' class \code{collection}. 232 | #' 233 | #' @export 234 | #' @examples 235 | #' library(reshape) 236 | #' irises <- melt(cbind(iris, Specimen=rep(1:50, 3)), 237 | #' id.vars=c("Species", "Specimen")) 238 | #' irisJSONstat <- toJSONstat(list(iris=irises)) 239 | #' cat(substr(irisJSONstat, 1, 76)) 240 | #' 241 | #' # Add indentation whitespace 242 | #' toJSONstat(as.data.frame(Titanic), value = "Freq", pretty = TRUE) 243 | toJSONstat <- function(x, value = "value", ...) { 244 | datasets <- c(list(version = unbox("2.0")), 245 | unravel(x, value)) 246 | 247 | toJSON(datasets, na = "null", ...) 248 | } 249 | 250 | unravel <- function(x, value) { 251 | assert(checkDataFrame(x), checkList(x)) 252 | if (is.data.frame(x)) { 253 | unravel_dataset(x, value) 254 | } else { 255 | assert_list(x, min.len = 1) 256 | list(class = unbox("collection"), 257 | link = list(item = unname(lapply(x, unravel, value)))) 258 | } 259 | } 260 | 261 | unravel_dataset <- function(dataset, value) { 262 | assert_data_frame(dataset, types = "atomic", min.rows = 1, min.cols = 2, 263 | col.names = "unique") 264 | assert_choice(value, names(dataset)) 265 | 266 | i <- vapply(dataset, is.raw, logical(1)) 267 | dataset[i] <- lapply(dataset[i], as.character) 268 | 269 | dimensions <- dataset[names(dataset) != value] 270 | assert_data_frame(dimensions, any.missing = FALSE) 271 | j <- !vapply(dimensions, is.factor, logical(1)) 272 | dimensions[j] <- lapply(dimensions[j], factor) 273 | 274 | dimension_sizes <- vapply(dimensions, nlevels, integer(1)) 275 | dimension_ids <- names(dimensions) 276 | categories <- lapply(dimensions, function(dimension) { 277 | list(category = list(index = levels(dimension))) 278 | }) 279 | 280 | dim_factors <- c(rev(cumprod(rev(dimension_sizes)))[-1], 1) 281 | 282 | sort_table <- lapply(dimensions, function(dimension) { 283 | unclass(dimension) - 1 284 | }) 285 | sort_table <- Map(`*`, sort_table, dim_factors) 286 | 287 | sort_index <- Reduce(`+`, sort_table) + 1 288 | 289 | if (any(duplicated(sort_index))) { 290 | stop("non-value columns must constitute a unique ID", call. = FALSE) 291 | } 292 | 293 | n <- prod(dimension_sizes) 294 | values <- dataset[[value]] 295 | if (length(values) == n) { 296 | values[sort_index] <- values 297 | } else { 298 | values <- lapply(values, unbox) 299 | names(values) <- sort_index - 1 300 | } 301 | 302 | datalist <- list(class = unbox("dataset"), 303 | id = dimension_ids, 304 | size = dimension_sizes, 305 | value = values, 306 | dimension = categories) 307 | 308 | datalist 309 | } 310 | -------------------------------------------------------------------------------- /inst/extdata/oecd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "dataset", 4 | "href" : "https://json-stat.org/samples/oecd.json", 5 | "label" : "Unemployment rate in the OECD countries 2003-2014", 6 | "note" : [ "Most of the data in this dataset are taken from the individual contributions of national correspondents appointed by the OECD Secretariat with the approval of the authorities of Member countries. Consequently, these data have not necessarily been harmonised at international level." ], 7 | "source" : "Economic Outlook No 92 - December 2012 - OECD Annual Projections", 8 | "updated" : "2012-11-27", 9 | "extension" : { 10 | "contact" : "EcoOutlook@oecd.org", 11 | "metadata" : [ 12 | { 13 | "title" : "Economic Outlook Policy and other assumptions underlying the projections Box 1.2 in General assessment", 14 | "href" : "http://www.oecd.org/eco/economicoutlookanalysisandforecasts/EO92macroeconomicsituation.pdf" 15 | }, 16 | { 17 | "title" : "Economic Outlook Sources and Methods", 18 | "href" : "http://www.oecd.org/document/22/0,3343,en_2649_34109_33702486_1_1_1_1,00.html" 19 | }, 20 | { 21 | "title" : "Database inventory (forthcoming)", 22 | "href" : "http://www.oecd.org/eco/databaseinventory" 23 | }, 24 | { 25 | "title" : "OECD Glossary", 26 | "href" : "http://stats.oecd.org/glossary/" 27 | } 28 | ] 29 | }, 30 | "value" : [5.943826289, 5.39663128, 5.044790587, 4.789362794, 4.379649386, 4.249093453, 5.592226603, 5.230660289, 5.099422942, 5.224336088, 5.50415003, 5.462866231, 4.278559338, 4.939707755, 5.152160612, 4.727182858, 4.399730726, 3.813933625, 4.776912506, 4.391591645, 4.143587245, 4.351345785, 4.695491708, 4.745323313, 8.158333333, 8.4, 8.483333333, 8.266666667, 7.466666667, 7.016666667, 7.891892855, 8.283171959, 7.175138783, 7.381153404, 7.689552898, 7.735442636, 7.594616751, 7.167833951, 6.748691501, 6.307841105, 6.049842626, 6.146014664, 8.284689299, 7.988900419, 7.453609598, 7.32358421, 7.169741525, 6.88122705, 9.5433848, 10.00149582, 9.224422554, 7.773166282, 7.150623348, 7.787221805, 10.80236438, 8.121579077, 7.104778251, 6.477468723, 6.78101031, 6.780198936, 7.818066527, 8.323638425, 7.922330988, 7.142271671, 5.316363283, 4.391669598, 6.675050668, 7.273107122, 6.723482523, 6.936394665, 7.242148075, 7.135151601, 5.344516646, 5.516904324, 4.793715416, 3.868296418, 3.669496447, 3.326692683, 5.821647379, 7.191696186, 7.313112408, 7.544640558, 7.357364231, 7.255659852, 10.03010116, 9.661753538, 7.899232972, 5.905173373, 4.659913473, 5.601684952, 13.87805579, 16.83438817, 12.4576855, 9.873121257, 9.116309666, 8.74566981, 9.017860131, 8.80435787, 8.368797468, 7.702632855, 6.850344695, 6.368216471, 8.269856093, 8.381534292, 7.774845319, 7.722836877, 7.962718148, 7.757742455, 8.503978378, 8.8650811, 8.882978134, 8.835277292, 8.009145174, 7.384897537, 9.129199553, 9.315864403, 9.202432489, 9.877166456, 10.66140443, 10.91985917, 9.134738857, 9.829230121, 10.69442137, 9.694756306, 8.310233377, 7.188163108, 7.429105355, 6.757338631, 5.752587233, 5.28775372, 5.524081118, 5.565600014, 9.712526535, 10.49281197, 9.849833119, 8.890878396, 8.276300402, 7.653084476, 9.460314273, 12.53058153, 17.65238747, 23.5737508, 26.6534591, 27.2364419, 5.860132523, 6.096400087, 7.185491402, 7.451740837, 7.35706148, 7.851089777, 10.0153875, 11.14448405, 10.92071597, 11.12538821, 11.09958634, 10.76358386, 3.352836045, 3.06335905, 2.590345651, 2.878830234, 2.301867378, 2.990597714, 7.241470693, 7.55861225, 7.058807671, 6.138731401, 5.393148124, 5.128315309, 4.739670964, 4.539966682, 4.341850838, 4.415526325, 4.571302023, 6.024123088, 11.81229736, 13.62078809, 14.51224844, 14.79227286, 14.73886731, 14.61076214, 13.28016732, 12.85704871, 11.29834866, 10.47596715, 9.147672881, 7.728344307, 9.476560711, 8.33683595, 7.110513831, 6.8731402, 7.359377644, 6.93094611, 8.444973801, 7.996760207, 7.708360512, 6.777043598, 6.110290905, 6.774113796, 7.800833899, 8.41234985, 8.438703909, 10.55546863, 11.42167502, 11.7584873, 5.25125, 4.717099486, 4.424423923, 4.129376275, 3.84841253, 3.979750388, 5.068375853, 5.058985674, 4.592622773, 4.399496241, 4.355894653, 4.286733019, 3.562065618, 3.67219364, 3.734708533, 3.450431799, 3.233335111, 3.15974989, 3.643064158, 3.715763348, 3.405129308, 3.378067785, 3.618601827, 3.397535556, 3.304883869, 3.710506994, 4.099797561, 4.242014975, 4.182611437, 4.14500326, 5.431987487, 5.778771292, 5.627283477, 6.078760003, 6.589474092, 6.658818611, 2.998805894, 3.695332444, 3.540173119, 3.550553518, 3.672170595, 3.949416134, 5.43621902, 5.373117407, 5.240905522, 5.036393758, 4.990182757, 4.897580596, 3.975713818, 4.894207123, 5.113659881, 4.20994586, 3.475695941, 3.018534226, 3.68444758, 4.383579198, 4.343866431, 5.163411369, 5.801548283, 6.10348765, 4.76074516, 4.018968583, 3.807106599, 3.840522581, 3.655294639, 4.160280272, 6.146341463, 6.537348623, 6.509125435, 6.938443309, 6.568824155, 6.048820957, 4.04172726, 4.186831741, 4.382939676, 3.392420144, 2.498729296, 2.565344859, 3.107969091, 3.521797592, 3.212318473, 3.098584692, 3.098584692, 3.003021166, 19.61702787, 18.97466246, 17.74593227, 13.84039072, 9.601554043, 7.117494731, 8.166610723, 9.622661542, 9.648757987, 10.05073744, 10.49463234, 10.66450371, 6.276549712, 6.666642728, 7.597516675, 7.637987286, 7.99012509, 7.607584033, 9.484363464, 10.81324061, 12.7097409, 15.52457602, 16.93137173, 16.62982306, 17.55389647, 18.22108629, 16.25634386, 13.3725907, 11.14262294, 9.507520125, 12.02516939, 14.37913326, 13.54138898, 13.69591839, 13.5763623, 12.97187212, 6.682102697, 6.291982582, 6.516689478, 5.945157013, 4.816202781, 4.368899066, 5.856004508, 7.240345922, 8.164977774, 8.529917685, 9.708595873, 9.847243093, 11.03816292, 10.54622939, 9.156961086, 8.511101588, 8.264570818, 11.33829871, 18.01195661, 20.06321219, 21.63712759, 25.04773498, 26.89014696, 26.78073067, 6.56574156, 7.373480411, 7.652096974, 7.053667613, 6.127066505, 6.183935584, 8.305635992, 8.372715009, 7.504247076, 7.651519753, 7.912693788, 7.604124855, 4.033356027, 4.31699694, 4.329724566, 3.941659077, 3.57509152, 3.341272685, 4.257833072, 4.44955058, 3.949110999, 3.863659425, 4.109877511, 3.999499419, 10.82310834, 10.58802629, 10.40296232, 10.01247258, 10.06182773, 10.74264555, 13.74762357, 11.65601928, 9.605142332, 9.014001387, 9.320782097, 8.651402638, 5.019884066, 4.768990278, 4.852538715, 5.450636437, 5.355104552, 5.708223236, 7.62507775, 7.861627732, 8.078635307, 8.027613742, 8.275155581, 8.036560522, 5.986539203, 5.523039996, 5.076780521, 4.617465075, 4.619105436, 5.800444743, 9.275245924, 9.627692959, 8.94612643, 8.091574662, 7.810715126, 7.514930043, 8.68886389, 8.942669403, 8.941482912, 8.233837469, 7.409607055, 7.436710115, 9.371745367, 9.891824566, 9.978460373, 11.11907575, 11.9135905, 11.99849464, 6.971079892, 6.859814025, 6.629153129, 6.100565063, 5.656171098, 5.982685271, 8.157564657, 8.320563893, 7.953121271, 7.970392182, 8.15379125, 8.004598637], 31 | "status" : {"10": "e", "11": "e", "22": "e", "23": "e", "34": "e", "35": "e", "46": "e", "47": "e", "58": "e", "59": "e", "70": "e", "71": "e", "82": "e", "83": "e", "94": "e", "95": "e", "106": "e", "107": "e", "118": "e", "119": "e", "130": "e", "131": "e", "142": "e", "143": "e", "154": "e", "155": "e", "166": "e", "167": "e", "178": "e", "179": "e", "190": "e", "191": "e", "202": "e", "203": "e", "214": "e", "215": "e", "226": "e", "227": "e", "238": "e", "239": "e", "250": "e", "251": "e", "262": "e", "263": "e", "274": "e", "275": "e", "286": "e", "287": "e", "298": "e", "299": "e", "310": "e", "311": "e", "322": "e", "323": "e", "334": "e", "335": "e", "346": "e", "347": "e", "358": "e", "359": "e", "370": "e", "371": "e", "382": "e", "383": "e", "394": "e", "395": "e", "406": "e", "407": "e", "418": "e", "419": "e", "430": "e", "431": "e"}, 32 | "id" : ["concept", "area", "year"], 33 | "size" : [1, 36, 12], 34 | "role" :{ 35 | "time" : ["year"], 36 | "geo" : ["area"], 37 | "metric" : ["concept"] 38 | }, 39 | "dimension" : { 40 | "concept" : { 41 | "label" : "indicator", 42 | "extension" : { 43 | "definition" : { 44 | "UNR" : "The OECD harmonised unemployment rate gives the number of unemployed persons as a percentage of the labour force (the total number of people employed plus unemployed)." 45 | } 46 | }, 47 | "category" : { 48 | "label" : { 49 | "UNR" : "unemployment rate" 50 | }, 51 | "unit" : { 52 | "UNR" : { 53 | "label" : "%", 54 | "decimals" : 9, 55 | "type" : "ratio", 56 | "base" : "per cent", 57 | "multiplier" : 0 58 | } 59 | } 60 | } 61 | }, 62 | 63 | "year" : { 64 | "label" : "2003-2014", 65 | "category" : { 66 | "index" : { 67 | "2003" : 0, 68 | "2004" : 1, 69 | "2005" : 2, 70 | "2006" : 3, 71 | "2007" : 4, 72 | "2008" : 5, 73 | "2009" : 6, 74 | "2010" : 7, 75 | "2011" : 8, 76 | "2012" : 9, 77 | "2013" : 10, 78 | "2014" : 11 79 | } 80 | } 81 | }, 82 | 83 | "area" : { 84 | "label" : "OECD countries, EU15 and total", 85 | "note" : [ "Except where otherwise indicated, data refer to the actual territory of the country considered." ], 86 | "category" : { 87 | "index" : { 88 | "AU" : 0, 89 | "AT" : 1, 90 | "BE" : 2, 91 | "CA" : 3, 92 | "CL" : 4, 93 | "CZ" : 5, 94 | "DK" : 6, 95 | "EE" : 7, 96 | "FI" : 8, 97 | "FR" : 9, 98 | "DE" : 10, 99 | "GR" : 11, 100 | "HU" : 12, 101 | "IS" : 13, 102 | "IE" : 14, 103 | "IL" : 15, 104 | "IT" : 16, 105 | "JP" : 17, 106 | "KR" : 18, 107 | "LU" : 19, 108 | "MX" : 20, 109 | "NL" : 21, 110 | "NZ" : 22, 111 | "NO" : 23, 112 | "PL" : 24, 113 | "PT" : 25, 114 | "SK" : 26, 115 | "SI" : 27, 116 | "ES" : 28, 117 | "SE" : 29, 118 | "CH" : 30, 119 | "TR" : 31, 120 | "UK" : 32, 121 | "US" : 33, 122 | "EU15" : 34, 123 | "OECD" : 35 124 | }, 125 | "label" : { 126 | "AU" : "Australia", 127 | "AT" : "Austria", 128 | "BE" : "Belgium", 129 | "CA" : "Canada", 130 | "CL" : "Chile", 131 | "CZ" : "Czech Republic", 132 | "DK" : "Denmark", 133 | "EE" : "Estonia", 134 | "FI" : "Finland", 135 | "FR" : "France", 136 | "DE" : "Germany", 137 | "GR" : "Greece", 138 | "HU" : "Hungary", 139 | "IS" : "Iceland", 140 | "IE" : "Ireland", 141 | "IL" : "Israel", 142 | "IT" : "Italy", 143 | "JP" : "Japan", 144 | "KR" : "Korea", 145 | "LU" : "Luxembourg", 146 | "MX" : "Mexico", 147 | "NL" : "Netherlands", 148 | "NZ" : "New Zealand", 149 | "NO" : "Norway", 150 | "PL" : "Poland", 151 | "PT" : "Portugal", 152 | "SK" : "Slovak Republic", 153 | "SI" : "Slovenia", 154 | "ES" : "Spain", 155 | "SE" : "Sweden", 156 | "CH" : "Switzerland", 157 | "TR" : "Turkey", 158 | "UK" : "United Kingdom", 159 | "US" : "United States", 160 | "EU15" : "Euro area (15 countries)", 161 | "OECD" : "total" 162 | }, 163 | "note" : { 164 | "DE" : [ "Germany (code DE) was created 3 October 1990 by the accession of the Democratic Republic of Germany (code DDR) to the then Federal Republic of Germany (code DEW)." ] 165 | }, 166 | "child" : { 167 | "EU15" : ["AT", "BE", "DE", "DK", "ES", "FI", "FR", "GR", "IE", "IT", "LU", "NL", "PT", "SE", "UK"], 168 | "OECD" : [ "EU15", "AU", "CA", "CL", "CZ", "DK", "EE", "HU", "IS", "IL", "JP", "KR", "MX", "NO", "NZ", "PL", "SK", "SI", "CH", "TR", "US"] 169 | } 170 | } 171 | } 172 | } 173 | } -------------------------------------------------------------------------------- /tests/testthat/oecd.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "dataset", 4 | "href" : "https://json-stat.org/samples/oecd.json", 5 | "label" : "Unemployment rate in the OECD countries 2003-2014", 6 | "note" : [ "Most of the data in this dataset are taken from the individual contributions of national correspondents appointed by the OECD Secretariat with the approval of the authorities of Member countries. Consequently, these data have not necessarily been harmonised at international level." ], 7 | "source" : "Economic Outlook No 92 - December 2012 - OECD Annual Projections", 8 | "updated" : "2012-11-27", 9 | "extension" : { 10 | "contact" : "EcoOutlook@oecd.org", 11 | "metadata" : [ 12 | { 13 | "title" : "Economic Outlook Policy and other assumptions underlying the projections Box 1.2 in General assessment", 14 | "href" : "http://www.oecd.org/eco/economicoutlookanalysisandforecasts/EO92macroeconomicsituation.pdf" 15 | }, 16 | { 17 | "title" : "Economic Outlook Sources and Methods", 18 | "href" : "http://www.oecd.org/document/22/0,3343,en_2649_34109_33702486_1_1_1_1,00.html" 19 | }, 20 | { 21 | "title" : "Database inventory (forthcoming)", 22 | "href" : "http://www.oecd.org/eco/databaseinventory" 23 | }, 24 | { 25 | "title" : "OECD Glossary", 26 | "href" : "http://stats.oecd.org/glossary/" 27 | } 28 | ] 29 | }, 30 | "value" : [5.943826289, 5.39663128, 5.044790587, 4.789362794, 4.379649386, 4.249093453, 5.592226603, 5.230660289, 5.099422942, 5.224336088, 5.50415003, 5.462866231, 4.278559338, 4.939707755, 5.152160612, 4.727182858, 4.399730726, 3.813933625, 4.776912506, 4.391591645, 4.143587245, 4.351345785, 4.695491708, 4.745323313, 8.158333333, 8.4, 8.483333333, 8.266666667, 7.466666667, 7.016666667, 7.891892855, 8.283171959, 7.175138783, 7.381153404, 7.689552898, 7.735442636, 7.594616751, 7.167833951, 6.748691501, 6.307841105, 6.049842626, 6.146014664, 8.284689299, 7.988900419, 7.453609598, 7.32358421, 7.169741525, 6.88122705, 9.5433848, 10.00149582, 9.224422554, 7.773166282, 7.150623348, 7.787221805, 10.80236438, 8.121579077, 7.104778251, 6.477468723, 6.78101031, 6.780198936, 7.818066527, 8.323638425, 7.922330988, 7.142271671, 5.316363283, 4.391669598, 6.675050668, 7.273107122, 6.723482523, 6.936394665, 7.242148075, 7.135151601, 5.344516646, 5.516904324, 4.793715416, 3.868296418, 3.669496447, 3.326692683, 5.821647379, 7.191696186, 7.313112408, 7.544640558, 7.357364231, 7.255659852, 10.03010116, 9.661753538, 7.899232972, 5.905173373, 4.659913473, 5.601684952, 13.87805579, 16.83438817, 12.4576855, 9.873121257, 9.116309666, 8.74566981, 9.017860131, 8.80435787, 8.368797468, 7.702632855, 6.850344695, 6.368216471, 8.269856093, 8.381534292, 7.774845319, 7.722836877, 7.962718148, 7.757742455, 8.503978378, 8.8650811, 8.882978134, 8.835277292, 8.009145174, 7.384897537, 9.129199553, 9.315864403, 9.202432489, 9.877166456, 10.66140443, 10.91985917, 9.134738857, 9.829230121, 10.69442137, 9.694756306, 8.310233377, 7.188163108, 7.429105355, 6.757338631, 5.752587233, 5.28775372, 5.524081118, 5.565600014, 9.712526535, 10.49281197, 9.849833119, 8.890878396, 8.276300402, 7.653084476, 9.460314273, 12.53058153, 17.65238747, 23.5737508, 26.6534591, 27.2364419, 5.860132523, 6.096400087, 7.185491402, 7.451740837, 7.35706148, 7.851089777, 10.0153875, 11.14448405, 10.92071597, 11.12538821, 11.09958634, 10.76358386, 3.352836045, 3.06335905, 2.590345651, 2.878830234, 2.301867378, 2.990597714, 7.241470693, 7.55861225, 7.058807671, 6.138731401, 5.393148124, 5.128315309, 4.739670964, 4.539966682, 4.341850838, 4.415526325, 4.571302023, 6.024123088, 11.81229736, 13.62078809, 14.51224844, 14.79227286, 14.73886731, 14.61076214, 13.28016732, 12.85704871, 11.29834866, 10.47596715, 9.147672881, 7.728344307, 9.476560711, 8.33683595, 7.110513831, 6.8731402, 7.359377644, 6.93094611, 8.444973801, 7.996760207, 7.708360512, 6.777043598, 6.110290905, 6.774113796, 7.800833899, 8.41234985, 8.438703909, 10.55546863, 11.42167502, 11.7584873, 5.25125, 4.717099486, 4.424423923, 4.129376275, 3.84841253, 3.979750388, 5.068375853, 5.058985674, 4.592622773, 4.399496241, 4.355894653, 4.286733019, 3.562065618, 3.67219364, 3.734708533, 3.450431799, 3.233335111, 3.15974989, 3.643064158, 3.715763348, 3.405129308, 3.378067785, 3.618601827, 3.397535556, 3.304883869, 3.710506994, 4.099797561, 4.242014975, 4.182611437, 4.14500326, 5.431987487, 5.778771292, 5.627283477, 6.078760003, 6.589474092, 6.658818611, 2.998805894, 3.695332444, 3.540173119, 3.550553518, 3.672170595, 3.949416134, 5.43621902, 5.373117407, 5.240905522, 5.036393758, 4.990182757, 4.897580596, 3.975713818, 4.894207123, 5.113659881, 4.20994586, 3.475695941, 3.018534226, 3.68444758, 4.383579198, 4.343866431, 5.163411369, 5.801548283, 6.10348765, 4.76074516, 4.018968583, 3.807106599, 3.840522581, 3.655294639, 4.160280272, 6.146341463, 6.537348623, 6.509125435, 6.938443309, 6.568824155, 6.048820957, 4.04172726, 4.186831741, 4.382939676, 3.392420144, 2.498729296, 2.565344859, 3.107969091, 3.521797592, 3.212318473, 3.098584692, 3.098584692, 3.003021166, 19.61702787, 18.97466246, 17.74593227, 13.84039072, 9.601554043, 7.117494731, 8.166610723, 9.622661542, 9.648757987, 10.05073744, 10.49463234, 10.66450371, 6.276549712, 6.666642728, 7.597516675, 7.637987286, 7.99012509, 7.607584033, 9.484363464, 10.81324061, 12.7097409, 15.52457602, 16.93137173, 16.62982306, 17.55389647, 18.22108629, 16.25634386, 13.3725907, 11.14262294, 9.507520125, 12.02516939, 14.37913326, 13.54138898, 13.69591839, 13.5763623, 12.97187212, 6.682102697, 6.291982582, 6.516689478, 5.945157013, 4.816202781, 4.368899066, 5.856004508, 7.240345922, 8.164977774, 8.529917685, 9.708595873, 9.847243093, 11.03816292, 10.54622939, 9.156961086, 8.511101588, 8.264570818, 11.33829871, 18.01195661, 20.06321219, 21.63712759, 25.04773498, 26.89014696, 26.78073067, 6.56574156, 7.373480411, 7.652096974, 7.053667613, 6.127066505, 6.183935584, 8.305635992, 8.372715009, 7.504247076, 7.651519753, 7.912693788, 7.604124855, 4.033356027, 4.31699694, 4.329724566, 3.941659077, 3.57509152, 3.341272685, 4.257833072, 4.44955058, 3.949110999, 3.863659425, 4.109877511, 3.999499419, 10.82310834, 10.58802629, 10.40296232, 10.01247258, 10.06182773, 10.74264555, 13.74762357, 11.65601928, 9.605142332, 9.014001387, 9.320782097, 8.651402638, 5.019884066, 4.768990278, 4.852538715, 5.450636437, 5.355104552, 5.708223236, 7.62507775, 7.861627732, 8.078635307, 8.027613742, 8.275155581, 8.036560522, 5.986539203, 5.523039996, 5.076780521, 4.617465075, 4.619105436, 5.800444743, 9.275245924, 9.627692959, 8.94612643, 8.091574662, 7.810715126, 7.514930043, 8.68886389, 8.942669403, 8.941482912, 8.233837469, 7.409607055, 7.436710115, 9.371745367, 9.891824566, 9.978460373, 11.11907575, 11.9135905, 11.99849464, 6.971079892, 6.859814025, 6.629153129, 6.100565063, 5.656171098, 5.982685271, 8.157564657, 8.320563893, 7.953121271, 7.970392182, 8.15379125, 8.004598637], 31 | "status" : {"10": "e", "11": "e", "22": "e", "23": "e", "34": "e", "35": "e", "46": "e", "47": "e", "58": "e", "59": "e", "70": "e", "71": "e", "82": "e", "83": "e", "94": "e", "95": "e", "106": "e", "107": "e", "118": "e", "119": "e", "130": "e", "131": "e", "142": "e", "143": "e", "154": "e", "155": "e", "166": "e", "167": "e", "178": "e", "179": "e", "190": "e", "191": "e", "202": "e", "203": "e", "214": "e", "215": "e", "226": "e", "227": "e", "238": "e", "239": "e", "250": "e", "251": "e", "262": "e", "263": "e", "274": "e", "275": "e", "286": "e", "287": "e", "298": "e", "299": "e", "310": "e", "311": "e", "322": "e", "323": "e", "334": "e", "335": "e", "346": "e", "347": "e", "358": "e", "359": "e", "370": "e", "371": "e", "382": "e", "383": "e", "394": "e", "395": "e", "406": "e", "407": "e", "418": "e", "419": "e", "430": "e", "431": "e"}, 32 | "id" : ["concept", "area", "year"], 33 | "size" : [1, 36, 12], 34 | "role" :{ 35 | "time" : ["year"], 36 | "geo" : ["area"], 37 | "metric" : ["concept"] 38 | }, 39 | "dimension" : { 40 | "concept" : { 41 | "label" : "indicator", 42 | "extension" : { 43 | "definition" : { 44 | "UNR" : "The OECD harmonised unemployment rate gives the number of unemployed persons as a percentage of the labour force (the total number of people employed plus unemployed)." 45 | } 46 | }, 47 | "category" : { 48 | "label" : { 49 | "UNR" : "unemployment rate" 50 | }, 51 | "unit" : { 52 | "UNR" : { 53 | "label" : "%", 54 | "decimals" : 9, 55 | "type" : "ratio", 56 | "base" : "per cent", 57 | "multiplier" : 0 58 | } 59 | } 60 | } 61 | }, 62 | 63 | "year" : { 64 | "label" : "2003-2014", 65 | "category" : { 66 | "index" : { 67 | "2003" : 0, 68 | "2004" : 1, 69 | "2005" : 2, 70 | "2006" : 3, 71 | "2007" : 4, 72 | "2008" : 5, 73 | "2009" : 6, 74 | "2010" : 7, 75 | "2011" : 8, 76 | "2012" : 9, 77 | "2013" : 10, 78 | "2014" : 11 79 | } 80 | } 81 | }, 82 | 83 | "area" : { 84 | "label" : "OECD countries, EU15 and total", 85 | "note" : [ "Except where otherwise indicated, data refer to the actual territory of the country considered." ], 86 | "category" : { 87 | "index" : { 88 | "AU" : 0, 89 | "AT" : 1, 90 | "BE" : 2, 91 | "CA" : 3, 92 | "CL" : 4, 93 | "CZ" : 5, 94 | "DK" : 6, 95 | "EE" : 7, 96 | "FI" : 8, 97 | "FR" : 9, 98 | "DE" : 10, 99 | "GR" : 11, 100 | "HU" : 12, 101 | "IS" : 13, 102 | "IE" : 14, 103 | "IL" : 15, 104 | "IT" : 16, 105 | "JP" : 17, 106 | "KR" : 18, 107 | "LU" : 19, 108 | "MX" : 20, 109 | "NL" : 21, 110 | "NZ" : 22, 111 | "NO" : 23, 112 | "PL" : 24, 113 | "PT" : 25, 114 | "SK" : 26, 115 | "SI" : 27, 116 | "ES" : 28, 117 | "SE" : 29, 118 | "CH" : 30, 119 | "TR" : 31, 120 | "UK" : 32, 121 | "US" : 33, 122 | "EU15" : 34, 123 | "OECD" : 35 124 | }, 125 | "label" : { 126 | "AU" : "Australia", 127 | "AT" : "Austria", 128 | "BE" : "Belgium", 129 | "CA" : "Canada", 130 | "CL" : "Chile", 131 | "CZ" : "Czech Republic", 132 | "DK" : "Denmark", 133 | "EE" : "Estonia", 134 | "FI" : "Finland", 135 | "FR" : "France", 136 | "DE" : "Germany", 137 | "GR" : "Greece", 138 | "HU" : "Hungary", 139 | "IS" : "Iceland", 140 | "IE" : "Ireland", 141 | "IL" : "Israel", 142 | "IT" : "Italy", 143 | "JP" : "Japan", 144 | "KR" : "Korea", 145 | "LU" : "Luxembourg", 146 | "MX" : "Mexico", 147 | "NL" : "Netherlands", 148 | "NZ" : "New Zealand", 149 | "NO" : "Norway", 150 | "PL" : "Poland", 151 | "PT" : "Portugal", 152 | "SK" : "Slovak Republic", 153 | "SI" : "Slovenia", 154 | "ES" : "Spain", 155 | "SE" : "Sweden", 156 | "CH" : "Switzerland", 157 | "TR" : "Turkey", 158 | "UK" : "United Kingdom", 159 | "US" : "United States", 160 | "EU15" : "Euro area (15 countries)", 161 | "OECD" : "total" 162 | }, 163 | "note" : { 164 | "DE" : [ "Germany (code DE) was created 3 October 1990 by the accession of the Democratic Republic of Germany (code DDR) to the then Federal Republic of Germany (code DEW)." ] 165 | }, 166 | "child" : { 167 | "EU15" : ["AT", "BE", "DE", "DK", "ES", "FI", "FR", "GR", "IE", "IT", "LU", "NL", "PT", "SE", "UK"], 168 | "OECD" : [ "EU15", "AU", "CA", "CL", "CZ", "DK", "EE", "HU", "IS", "IL", "JP", "KR", "MX", "NO", "NZ", "PL", "SK", "SI", "CH", "TR", "US"] 169 | } 170 | } 171 | } 172 | } 173 | } -------------------------------------------------------------------------------- /tests/testthat/oecd-canada-col.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "collection", 4 | "href" : "https://json-stat.org/samples/oecd-canada-col.json", 5 | "label" : "OECD-Canada Sample Collection", 6 | "updated" : "2015-12-24", 7 | "link" : { 8 | "item" : [ 9 | { 10 | "class" : "dataset", 11 | "href" : "https://json-stat.org/samples/oecd.json", 12 | "label" : "Unemployment rate in the OECD countries 2003-2014", 13 | "note" : [ "Most of the data in this dataset are taken from the individual contributions of national correspondents appointed by the OECD Secretariat with the approval of the authorities of Member countries. Consequently, these data have not necessarily been harmonised at international level." ], 14 | "source" : "Economic Outlook No 92 - December 2012 - OECD Annual Projections", 15 | "updated" : "2012-11-27", 16 | "extension" : { 17 | "contact" : "EcoOutlook@oecd.org", 18 | "metadata" : [ 19 | { 20 | "title" : "Economic Outlook Policy and other assumptions underlying the projections Box 1.2 in General assessment", 21 | "href" : "http://www.oecd.org/eco/economicoutlookanalysisandforecasts/EO92macroeconomicsituation.pdf" 22 | }, 23 | { 24 | "title" : "Economic Outlook Sources and Methods", 25 | "href" : "http://www.oecd.org/document/22/0,3343,en_2649_34109_33702486_1_1_1_1,00.html" 26 | }, 27 | { 28 | "title" : "Database inventory (forthcoming)", 29 | "href" : "http://www.oecd.org/eco/databaseinventory" 30 | }, 31 | { 32 | "title" : "OECD Glossary", 33 | "href" : "http://stats.oecd.org/glossary/" 34 | } 35 | ] 36 | }, 37 | "value" : [5.943826289, 5.39663128, 5.044790587, 4.789362794, 4.379649386, 4.249093453, 5.592226603, 5.230660289, 5.099422942, 5.224336088, 5.50415003, 5.462866231, 4.278559338, 4.939707755, 5.152160612, 4.727182858, 4.399730726, 3.813933625, 4.776912506, 4.391591645, 4.143587245, 4.351345785, 4.695491708, 4.745323313, 8.158333333, 8.4, 8.483333333, 8.266666667, 7.466666667, 7.016666667, 7.891892855, 8.283171959, 7.175138783, 7.381153404, 7.689552898, 7.735442636, 7.594616751, 7.167833951, 6.748691501, 6.307841105, 6.049842626, 6.146014664, 8.284689299, 7.988900419, 7.453609598, 7.32358421, 7.169741525, 6.88122705, 9.5433848, 10.00149582, 9.224422554, 7.773166282, 7.150623348, 7.787221805, 10.80236438, 8.121579077, 7.104778251, 6.477468723, 6.78101031, 6.780198936, 7.818066527, 8.323638425, 7.922330988, 7.142271671, 5.316363283, 4.391669598, 6.675050668, 7.273107122, 6.723482523, 6.936394665, 7.242148075, 7.135151601, 5.344516646, 5.516904324, 4.793715416, 3.868296418, 3.669496447, 3.326692683, 5.821647379, 7.191696186, 7.313112408, 7.544640558, 7.357364231, 7.255659852, 10.03010116, 9.661753538, 7.899232972, 5.905173373, 4.659913473, 5.601684952, 13.87805579, 16.83438817, 12.4576855, 9.873121257, 9.116309666, 8.74566981, 9.017860131, 8.80435787, 8.368797468, 7.702632855, 6.850344695, 6.368216471, 8.269856093, 8.381534292, 7.774845319, 7.722836877, 7.962718148, 7.757742455, 8.503978378, 8.8650811, 8.882978134, 8.835277292, 8.009145174, 7.384897537, 9.129199553, 9.315864403, 9.202432489, 9.877166456, 10.66140443, 10.91985917, 9.134738857, 9.829230121, 10.69442137, 9.694756306, 8.310233377, 7.188163108, 7.429105355, 6.757338631, 5.752587233, 5.28775372, 5.524081118, 5.565600014, 9.712526535, 10.49281197, 9.849833119, 8.890878396, 8.276300402, 7.653084476, 9.460314273, 12.53058153, 17.65238747, 23.5737508, 26.6534591, 27.2364419, 5.860132523, 6.096400087, 7.185491402, 7.451740837, 7.35706148, 7.851089777, 10.0153875, 11.14448405, 10.92071597, 11.12538821, 11.09958634, 10.76358386, 3.352836045, 3.06335905, 2.590345651, 2.878830234, 2.301867378, 2.990597714, 7.241470693, 7.55861225, 7.058807671, 6.138731401, 5.393148124, 5.128315309, 4.739670964, 4.539966682, 4.341850838, 4.415526325, 4.571302023, 6.024123088, 11.81229736, 13.62078809, 14.51224844, 14.79227286, 14.73886731, 14.61076214, 13.28016732, 12.85704871, 11.29834866, 10.47596715, 9.147672881, 7.728344307, 9.476560711, 8.33683595, 7.110513831, 6.8731402, 7.359377644, 6.93094611, 8.444973801, 7.996760207, 7.708360512, 6.777043598, 6.110290905, 6.774113796, 7.800833899, 8.41234985, 8.438703909, 10.55546863, 11.42167502, 11.7584873, 5.25125, 4.717099486, 4.424423923, 4.129376275, 3.84841253, 3.979750388, 5.068375853, 5.058985674, 4.592622773, 4.399496241, 4.355894653, 4.286733019, 3.562065618, 3.67219364, 3.734708533, 3.450431799, 3.233335111, 3.15974989, 3.643064158, 3.715763348, 3.405129308, 3.378067785, 3.618601827, 3.397535556, 3.304883869, 3.710506994, 4.099797561, 4.242014975, 4.182611437, 4.14500326, 5.431987487, 5.778771292, 5.627283477, 6.078760003, 6.589474092, 6.658818611, 2.998805894, 3.695332444, 3.540173119, 3.550553518, 3.672170595, 3.949416134, 5.43621902, 5.373117407, 5.240905522, 5.036393758, 4.990182757, 4.897580596, 3.975713818, 4.894207123, 5.113659881, 4.20994586, 3.475695941, 3.018534226, 3.68444758, 4.383579198, 4.343866431, 5.163411369, 5.801548283, 6.10348765, 4.76074516, 4.018968583, 3.807106599, 3.840522581, 3.655294639, 4.160280272, 6.146341463, 6.537348623, 6.509125435, 6.938443309, 6.568824155, 6.048820957, 4.04172726, 4.186831741, 4.382939676, 3.392420144, 2.498729296, 2.565344859, 3.107969091, 3.521797592, 3.212318473, 3.098584692, 3.098584692, 3.003021166, 19.61702787, 18.97466246, 17.74593227, 13.84039072, 9.601554043, 7.117494731, 8.166610723, 9.622661542, 9.648757987, 10.05073744, 10.49463234, 10.66450371, 6.276549712, 6.666642728, 7.597516675, 7.637987286, 7.99012509, 7.607584033, 9.484363464, 10.81324061, 12.7097409, 15.52457602, 16.93137173, 16.62982306, 17.55389647, 18.22108629, 16.25634386, 13.3725907, 11.14262294, 9.507520125, 12.02516939, 14.37913326, 13.54138898, 13.69591839, 13.5763623, 12.97187212, 6.682102697, 6.291982582, 6.516689478, 5.945157013, 4.816202781, 4.368899066, 5.856004508, 7.240345922, 8.164977774, 8.529917685, 9.708595873, 9.847243093, 11.03816292, 10.54622939, 9.156961086, 8.511101588, 8.264570818, 11.33829871, 18.01195661, 20.06321219, 21.63712759, 25.04773498, 26.89014696, 26.78073067, 6.56574156, 7.373480411, 7.652096974, 7.053667613, 6.127066505, 6.183935584, 8.305635992, 8.372715009, 7.504247076, 7.651519753, 7.912693788, 7.604124855, 4.033356027, 4.31699694, 4.329724566, 3.941659077, 3.57509152, 3.341272685, 4.257833072, 4.44955058, 3.949110999, 3.863659425, 4.109877511, 3.999499419, 10.82310834, 10.58802629, 10.40296232, 10.01247258, 10.06182773, 10.74264555, 13.74762357, 11.65601928, 9.605142332, 9.014001387, 9.320782097, 8.651402638, 5.019884066, 4.768990278, 4.852538715, 5.450636437, 5.355104552, 5.708223236, 7.62507775, 7.861627732, 8.078635307, 8.027613742, 8.275155581, 8.036560522, 5.986539203, 5.523039996, 5.076780521, 4.617465075, 4.619105436, 5.800444743, 9.275245924, 9.627692959, 8.94612643, 8.091574662, 7.810715126, 7.514930043, 8.68886389, 8.942669403, 8.941482912, 8.233837469, 7.409607055, 7.436710115, 9.371745367, 9.891824566, 9.978460373, 11.11907575, 11.9135905, 11.99849464, 6.971079892, 6.859814025, 6.629153129, 6.100565063, 5.656171098, 5.982685271, 8.157564657, 8.320563893, 7.953121271, 7.970392182, 8.15379125, 8.004598637], 38 | "status" : {"10": "e", "11": "e", "22": "e", "23": "e", "34": "e", "35": "e", "46": "e", "47": "e", "58": "e", "59": "e", "70": "e", "71": "e", "82": "e", "83": "e", "94": "e", "95": "e", "106": "e", "107": "e", "118": "e", "119": "e", "130": "e", "131": "e", "142": "e", "143": "e", "154": "e", "155": "e", "166": "e", "167": "e", "178": "e", "179": "e", "190": "e", "191": "e", "202": "e", "203": "e", "214": "e", "215": "e", "226": "e", "227": "e", "238": "e", "239": "e", "250": "e", "251": "e", "262": "e", "263": "e", "274": "e", "275": "e", "286": "e", "287": "e", "298": "e", "299": "e", "310": "e", "311": "e", "322": "e", "323": "e", "334": "e", "335": "e", "346": "e", "347": "e", "358": "e", "359": "e", "370": "e", "371": "e", "382": "e", "383": "e", "394": "e", "395": "e", "406": "e", "407": "e", "418": "e", "419": "e", "430": "e", "431": "e"}, 39 | "id" : ["concept", "area", "year"], 40 | "size" : [1, 36, 12], 41 | "role" :{ 42 | "time" : ["year"], 43 | "geo" : ["area"], 44 | "metric" : ["concept"] 45 | }, 46 | "dimension" : { 47 | "concept" : { 48 | "label" : "indicator", 49 | "extension" : { 50 | "definition" : { 51 | "UNR" : "The OECD harmonised unemployment rate gives the number of unemployed persons as a percentage of the labour force (the total number of people employed plus unemployed)." 52 | } 53 | }, 54 | "category" : { 55 | "label" : { 56 | "UNR" : "unemployment rate" 57 | }, 58 | "unit" : { 59 | "UNR" : { 60 | "label" : "%", 61 | "decimals" : 9, 62 | "type" : "ratio", 63 | "base" : "per cent", 64 | "multiplier" : 0 65 | } 66 | } 67 | } 68 | }, 69 | 70 | "year" : { 71 | "label" : "2003-2014", 72 | "category" : { 73 | "index" : { 74 | "2003" : 0, 75 | "2004" : 1, 76 | "2005" : 2, 77 | "2006" : 3, 78 | "2007" : 4, 79 | "2008" : 5, 80 | "2009" : 6, 81 | "2010" : 7, 82 | "2011" : 8, 83 | "2012" : 9, 84 | "2013" : 10, 85 | "2014" : 11 86 | } 87 | } 88 | }, 89 | 90 | "area" : { 91 | "label" : "OECD countries, EU15 and total", 92 | "note" : [ "Except where otherwise indicated, data refer to the actual territory of the country considered." ], 93 | "category" : { 94 | "index" : { 95 | "AU" : 0, 96 | "AT" : 1, 97 | "BE" : 2, 98 | "CA" : 3, 99 | "CL" : 4, 100 | "CZ" : 5, 101 | "DK" : 6, 102 | "EE" : 7, 103 | "FI" : 8, 104 | "FR" : 9, 105 | "DE" : 10, 106 | "GR" : 11, 107 | "HU" : 12, 108 | "IS" : 13, 109 | "IE" : 14, 110 | "IL" : 15, 111 | "IT" : 16, 112 | "JP" : 17, 113 | "KR" : 18, 114 | "LU" : 19, 115 | "MX" : 20, 116 | "NL" : 21, 117 | "NZ" : 22, 118 | "NO" : 23, 119 | "PL" : 24, 120 | "PT" : 25, 121 | "SK" : 26, 122 | "SI" : 27, 123 | "ES" : 28, 124 | "SE" : 29, 125 | "CH" : 30, 126 | "TR" : 31, 127 | "UK" : 32, 128 | "US" : 33, 129 | "EU15" : 34, 130 | "OECD" : 35 131 | }, 132 | "label" : { 133 | "AU" : "Australia", 134 | "AT" : "Austria", 135 | "BE" : "Belgium", 136 | "CA" : "Canada", 137 | "CL" : "Chile", 138 | "CZ" : "Czech Republic", 139 | "DK" : "Denmark", 140 | "EE" : "Estonia", 141 | "FI" : "Finland", 142 | "FR" : "France", 143 | "DE" : "Germany", 144 | "GR" : "Greece", 145 | "HU" : "Hungary", 146 | "IS" : "Iceland", 147 | "IE" : "Ireland", 148 | "IL" : "Israel", 149 | "IT" : "Italy", 150 | "JP" : "Japan", 151 | "KR" : "Korea", 152 | "LU" : "Luxembourg", 153 | "MX" : "Mexico", 154 | "NL" : "Netherlands", 155 | "NZ" : "New Zealand", 156 | "NO" : "Norway", 157 | "PL" : "Poland", 158 | "PT" : "Portugal", 159 | "SK" : "Slovak Republic", 160 | "SI" : "Slovenia", 161 | "ES" : "Spain", 162 | "SE" : "Sweden", 163 | "CH" : "Switzerland", 164 | "TR" : "Turkey", 165 | "UK" : "United Kingdom", 166 | "US" : "United States", 167 | "EU15" : "Euro area (15 countries)", 168 | "OECD" : "total" 169 | }, 170 | "note" : { 171 | "DE" : [ "Germany (code DE) was created 3 October 1990 by the accession of the Democratic Republic of Germany (code DDR) to the then Federal Republic of Germany (code DEW)." ] 172 | }, 173 | "child" : { 174 | "EU15" : ["AT", "BE", "DE", "DK", "ES", "FI", "FR", "GR", "IE", "IT", "LU", "NL", "PT", "SE", "UK"], 175 | "OECD" : [ "EU15", "AU", "CA", "CL", "CZ", "DK", "EE", "HU", "IS", "IL", "JP", "KR", "MX", "NO", "NZ", "PL", "SK", "SI", "CH", "TR", "US"] 176 | } 177 | } 178 | } 179 | } 180 | }, 181 | { 182 | "class" : "dataset", 183 | "href" : "https://json-stat.org/samples/canada.json", 184 | "label" : "Population by sex and age group. Canada. 2012", 185 | "source" : "Statistics Canada, CANSIM, table 051-0001", 186 | "updated" : "2012-09-27", 187 | "value" : [34880.5, 17309.1, 17571.3, 100.0, 100.0, 100.0, 1928.8, 988.7, 940.1, 5.5, 5.7, 5.3, 1857.1, 955.0, 902.1, 5.3, 5.5, 5.1, 1877.3, 964.7, 912.6, 5.4, 5.6, 5.2, 2163.0, 1108.2, 1054.7, 6.2, 6.4, 6.0, 2441.1, 1254.2, 1186.9, 7.0, 7.2, 6.8, 2452.3, 1246.8, 1205.5, 7.0, 7.2, 6.9, 2406.3, 1203.5, 1202.8, 6.9, 7.0, 6.8, 2307.2, 1155.2, 1152.0, 6.6, 6.7, 6.6, 2384.6, 1199.4, 1185.2, 6.8, 6.9, 6.7, 2681.3, 1350.1, 1331.2, 7.7, 7.8, 7.6, 2703.2, 1352.3, 1350.9, 7.7, 7.8, 7.7, 2428.5, 1199.0, 1229.5, 7.0, 6.9, 7.0, 2063.0, 1010.2, 1052.8, 5.9, 5.8, 6.0, 1645.1, 797.9, 847.2, 4.7, 4.6, 4.8, 1190.7, 563.8, 626.8, 3.4, 3.3, 3.6, 924.1, 418.9, 505.2, 2.6, 2.4, 2.9, 718.8, 303.6, 415.2, 2.1, 1.8, 2.4, 451.0, 164.1, 286.9, 1.3, 0.9, 1.6, 257.1, 73.2, 183.9, 0.7, 0.4, 1.0], 188 | "status" : ["a"], 189 | "id" : ["country", "year", "age", "concept", "sex"], 190 | "size" : [1, 1, 20, 2, 3], 191 | "role" :{ 192 | "time" : ["year"], 193 | "geo" : ["country"], 194 | "metric" : ["concept"] 195 | }, 196 | "dimension" : { 197 | "concept" : { 198 | "label" : "concepts", 199 | "category" : { 200 | "index" : { 201 | "POP" : 0, 202 | "PERCENT" : 1 203 | }, 204 | "label" : { 205 | "POP" : "population", 206 | "PERCENT" : "weight of age group in the population" 207 | }, 208 | "unit" : { 209 | "POP" : { 210 | "label": "thousands of persons", 211 | "decimals": 1, 212 | "type" : "count", 213 | "base" : "people", 214 | "multiplier" : 3 215 | }, 216 | "PERCENT" : { 217 | "label" : "%", 218 | "decimals": 1, 219 | "type" : "ratio", 220 | "base" : "per cent", 221 | "multiplier" : 0 222 | } 223 | } 224 | } 225 | }, 226 | 227 | "year" : { 228 | "label" : "year", 229 | "category" : { 230 | "index" : { 231 | "2012" : 0 232 | } 233 | } 234 | }, 235 | 236 | "country" : { 237 | "label" : "country", 238 | "category" : { 239 | "label" : { 240 | "CA" : "Canada" 241 | } 242 | } 243 | }, 244 | 245 | "age" : { 246 | "label" : "age group", 247 | "category" : { 248 | "index" : [ 249 | "T", 250 | "4", 251 | "9", 252 | "14", 253 | "19", 254 | "24", 255 | "29", 256 | "34", 257 | "39", 258 | "44", 259 | "49", 260 | "54", 261 | "59", 262 | "64", 263 | "69", 264 | "74", 265 | "79", 266 | "84", 267 | "89", 268 | "older" 269 | ], 270 | "label" : { 271 | "T": "total", 272 | "4": "0 to 4", 273 | "9": "5 to 9", 274 | "14": "10 to 14", 275 | "19": "15 to 19", 276 | "24": "20 to 24", 277 | "29": "25 to 29", 278 | "34": "30 to 34", 279 | "39": "35 to 39", 280 | "44": "40 to 44", 281 | "49": "45 to 49", 282 | "54": "50 to 54", 283 | "59": "55 to 59", 284 | "64": "60 to 64", 285 | "69": "65 to 69", 286 | "74": "70 to 74", 287 | "79": "75 to 79", 288 | "84": "80 to 84", 289 | "89": "85 to 89", 290 | "older": "90 and older" 291 | } 292 | } 293 | }, 294 | 295 | "sex" : { 296 | "label" : "sex", 297 | 298 | "link" : { 299 | "alternate" : [ 300 | { 301 | "type" : "text/html", 302 | "href" : "http://www.statcan.gc.ca/concepts/definitions/class-sex-eng.htm" 303 | } 304 | ] 305 | }, 306 | "category" : { 307 | "index" : ["T", "M", "F"], 308 | "label" : { 309 | "T" : "total", 310 | "M" : "male", 311 | "F" : "female" 312 | } 313 | } 314 | } 315 | } 316 | } 317 | ] 318 | } 319 | } -------------------------------------------------------------------------------- /tests/testthat/galicia.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : "2.0", 3 | "class" : "dataset", 4 | "href" : "https://json-stat.org/samples/galicia.json", 5 | "label" : "Population by province of residence, place of birth, age, gender and year in Galicia", 6 | "source" : "INE and IGE", 7 | "updated" : "2012-12-27T12:25:09Z", 8 | "value" : [2695880,1096027,357648,338446,903759,2772928,1141286,348067,328697,954877,1294378,525388,173339,161968,433683,1341269,549283,169376,158758,463853,1401502,570639,184309,176478,470076,1431658,592004,178692,169939,491024,94722,38504,9991,9364,36863,113118,47928,11252,10574,43364,48723,19757,5090,4830,19046,58669,24796,5710,5476,22687,45999,18747,4901,4534,17817,54449,23132,5542,5098,20677,101884,40697,11500,11161,38526,109678,45491,10833,10531,42822,52343,20844,5818,5819,19862,56623,23352,5626,5416,22230,49541,19853,5682,5342,18664,53055,22140,5207,5115,20593,122960,48899,14843,13668,45550,104734,42888,11176,10389,40281,62994,25108,7589,6938,23359,54063,22121,5712,5335,20896,59966,23791,7254,6730,22191,50671,20767,5464,5054,19385,157255,63920,19036,17447,56852,111475,44587,12615,12264,42010,80408,32665,9630,9014,29099,57320,22767,6429,6393,21730,76847,31255,9406,8433,27753,54156,21819,6186,5871,20280,207668,85392,23538,22348,76390,132761,53232,16119,14823,48587,105460,43477,12036,11348,38599,67613,27065,8215,7498,24834,102208,41915,11502,11000,37791,65149,26167,7904,7325,23752,213916,89288,23541,22813,78274,165935,68441,20045,18111,59339,107324,44906,11646,11372,39400,84038,34355,10189,9252,30242,106592,44382,11895,11441,38874,81897,34086,9855,8858,29097,201933,83854,23696,22117,72266,216539,90743,24405,21978,79412,100260,41391,11809,11037,36023,109506,45746,12535,11183,40042,101673,42463,11887,11080,36243,107033,44997,11871,10795,39370,193792,81111,24717,21536,66428,226550,95746,24490,22788,83526,95461,39761,12388,10633,32679,114140,48039,12322,11459,42319,98331,41350,12329,10903,33749,112409,47706,12167,11328,41207,191581,79605,24986,22300,64690,215378,90301,24851,22947,77279,94722,39201,12862,11119,31540,107505,44568,12417,11612,38908,96859,40404,12124,11181,33150,107873,45733,12434,11335,38371,174440,72850,22437,20194,58959,203232,85284,25570,22546,69832,86781,36034,11818,10278,28651,100436,41846,12784,11184,34621,87659,36816,10619,9916,30308,102796,43438,12786,11361,35211,168933,71342,20672,20358,56561,196554,81770,25371,23065,66348,83531,34919,10643,10173,27796,97195,40152,13015,11518,32510,85402,36423,10029,10185,28765,99359,41618,12356,11546,33838,163648,68271,20867,21525,52985,176206,73320,22699,20888,59300,79465,33030,10282,10407,25746,86745,35827,11792,10502,28624,84183,35241,10585,11118,27239,89461,37492,10908,10386,30675,135825,55269,19697,19304,41555,168390,70627,20745,21087,55930,63800,26090,9261,9017,19432,81692,33801,10495,10335,27061,72025,29179,10436,10287,22123,86697,36826,10250,10752,28869,169232,67381,26384,26067,49400,160341,66421,20725,22104,51091,77457,30684,12368,12163,22242,75914,31248,9990,10542,24134,91775,36697,14016,13904,27158,84427,35172,10736,11563,26956,143719,55857,24503,22950,40409,126758,51247,18633,18513,38366,63169,24305,11214,10371,17279,57309,23170,8484,8520,17136,80550,31552,13289,12579,23130,69449,28077,10149,9994,21230,112769,41941,20843,19568,30417,144226,57443,22610,22431,41742,45634,16650,9020,8348,11616,61377,24187,9919,9936,17335,67135,25291,11823,11220,18801,82850,33256,12691,12495,24407,76402,28335,14123,13420,20524,105472,40834,18116,16909,29613,27330,9787,5530,5185,6828,41105,15677,7438,6934,11056,49072,18548,8593,8235,13696,64367,25157,10678,9975,18557,43981,15865,8189,8276,11651,62347,22948,11542,10797,17061,13750,4860,2920,2733,3237,21011,7465,4303,3949,5294,30231,11005,5269,5543,8414,41336,15483,7239,6848,11767,15294,5455,2970,2918,3951,25493,9387,4781,4477,6848,4786,1609,1160,984,1033,7191,2479,1564,1390,1758,12325,4523,2150,2266,3386,18302,6908,3218,3087,5089,3718,1396,693,705,924,6715,2328,1277,1276,1833,887,290,227,183,187,1603,560,372,291,380,2831,1106,466,522,737,5111,1768,905,986,1453,391,118,82,75,116,1025,322,211,199,293,93,20,28,16,29,213,60,64,34,55,298,98,54,59,87,812,262,147,164,238,1695355,642736,239519,202971,610129,1579732,600831,212365,176156,590381,822813,312530,120034,98290,291959,770929,292759,106782,86316,285072,872542,330206,119485,104681,318170,808803,308072,105583,89840,305308,76971,29388,8643,7339,31601,92261,37386,9709,8312,36854,39610,15105,4425,3792,16288,47862,19268,4960,4340,19294,37361,14283,4218,3547,15313,44399,18118,4750,3972,17560,77607,28972,9552,8039,31044,80896,31486,8466,7367,33576,39882,14837,4831,4151,16063,41885,16228,4392,3784,17481,37725,14135,4721,3888,14981,39011,15258,4075,3583,16095,92266,35037,11945,9239,36045,72245,27788,8188,6667,29602,47384,18051,6099,4712,18522,37324,14343,4195,3415,15371,44882,16986,5846,4527,17523,34921,13445,3993,3252,14231,117043,45957,14810,11697,44579,74576,27779,9176,7596,30025,60048,23632,7514,6072,22830,38397,14188,4673,3953,15583,56995,22325,7296,5625,21749,36179,13591,4503,3642,14442,148915,59411,17347,14033,58124,86449,32674,11229,8426,34120,76715,30742,8991,7353,29629,44705,16953,5820,4322,17610,72200,28669,8356,6680,28495,41744,15720,5409,4103,16511,137504,54823,15566,12656,54459,98694,38509,12570,9419,38196,70887,28413,8046,6557,27871,51627,20103,6553,5004,19967,66617,26410,7520,6099,26588,47068,18405,6018,4415,18229,114435,44003,14094,11169,45169,115228,44879,13376,10201,46772,58979,22583,7594,6016,22786,59997,23438,7142,5460,23957,55456,21420,6500,5153,22383,55232,21441,6234,4742,22815,103254,39692,14095,10068,39399,108529,41710,12277,9372,45171,52328,20072,7623,5357,19276,55725,21434,6454,4908,22929,50926,19620,6472,4711,20123,52804,20277,5822,4463,22242,101162,38626,14167,10666,37703,101273,38274,12354,9447,41198,51775,19802,7863,5715,18395,51344,19237,6630,5103,20373,49387,18824,6304,4951,19308,49929,19036,5724,4344,20825,92890,35799,12817,10175,34099,97768,37270,13216,9587,37696,47384,18316,7126,5403,16539,48976,18575,7118,5054,18229,45506,17483,5691,4772,17560,48792,18694,6098,4533,19466,92580,36229,12478,10901,32972,97952,37232,13691,10488,36541,46254,18084,6675,5605,15890,49636,18852,7522,5555,17708,46326,18145,5803,5296,17082,48316,18381,6169,4933,18833,93052,35477,13206,12301,32068,90412,34610,12521,10244,33037,44925,17197,6659,5903,15166,45210,17348,6812,5323,15726,48127,18280,6547,6398,16902,45202,17262,5709,4921,17310,80456,29707,12998,11539,26212,89743,34824,12256,11049,31615,36933,13730,6248,5242,11713,43642,16861,6399,5508,14873,43523,15977,6750,6297,14499,46102,17963,5857,5540,16741,106541,38829,18048,16859,32805,88949,33706,12785,12319,30139,48177,17436,8705,7774,14262,41617,15699,6296,5869,13754,58364,21393,9343,9085,18543,47332,18008,6489,6450,16385,92977,33438,16844,15142,27553,73085,26925,11919,10786,23456,40726,14446,8006,6731,11543,32211,11907,5549,4854,9900,52251,18992,8838,8411,16010,40874,15018,6369,5932,13556,74142,25595,14412,13435,20700,88144,32182,15054,13976,26933,29969,10133,6464,5676,7696,36972,13336,6781,6094,10761,44173,15462,7948,7759,13004,51172,18846,8273,7882,16172,50188,17271,9771,9161,13985,65217,23516,11950,10524,19227,17978,5979,3952,3525,4522,25403,8949,5158,4260,7035,32210,11292,5819,5636,9463,39815,14567,6792,6263,12192,29070,9692,5766,5772,7840,38285,13241,7564,6754,10727,8920,2801,2132,1871,2116,12942,4279,2965,2472,3225,20150,6891,3634,3901,5724,25344,8962,4598,4281,7502,10348,3427,2167,2004,2750,15360,5338,3084,2699,4239,3265,986,887,694,698,4381,1435,1058,839,1049,8308,2873,1521,1541,2373,10979,3903,2026,1860,3191,2474,860,496,492,626,4015,1305,830,793,1086,609,174,174,126,135,936,290,257,172,217,1865,686,322,366,491,3079,1015,573,621,870,255,71,56,53,75,648,197,149,131,172,65,11,20,15,19,139,35,48,25,31,190,60,36,38,56,510,162,101,105,142,591569,289921,74279,78981,148388,655747,321573,74995,82655,176524,278166,135651,32807,36948,72760,311911,152407,33202,38907,87394,313403,154270,41472,42033,75628,343836,169166,41792,43748,89130,12273,7020,723,1118,3412,14606,7980,730,1443,4454,6307,3601,344,581,1781,7580,4161,343,737,2338,5966,3419,379,537,1631,7026,3818,386,705,2116,14719,7916,985,1512,4306,16121,8794,830,1536,4961,7520,4012,493,813,2202,8432,4590,449,813,2580,7199,3904,492,699,2104,7689,4204,381,722,2381,17068,8682,1408,2023,4955,16727,8738,1076,1606,5306,8715,4447,710,1022,2536,8608,4514,527,839,2728,8353,4235,698,1001,2419,8119,4224,549,768,2578,21986,11040,2036,2614,6296,18589,9410,1321,2013,5845,11071,5509,1018,1338,3206,9531,4801,647,1075,3008,10915,5531,1018,1276,3090,9058,4609,673,938,2837,30039,15189,2515,3400,8935,21648,10688,1925,2551,6484,14721,7585,1183,1605,4348,10842,5369,908,1296,3270,15318,7604,1332,1795,4587,10805,5319,1016,1255,3214,36898,18906,3212,3837,10943,31175,15323,2912,3444,9497,17578,9076,1387,1777,5338,15173,7458,1383,1707,4625,19320,9830,1825,2060,5605,16001,7864,1529,1737,4872,46198,22738,4852,4956,13652,48950,24544,4221,4692,15493,21863,10782,2034,2246,6801,24052,12210,1901,2275,7666,24335,11956,2818,2710,6851,24898,12334,2321,2417,7827,50810,24775,6322,5995,13718,55988,28581,4750,5220,17438,24582,11943,2782,2814,7043,27776,14245,2141,2497,8893,26228,12832,3540,3181,6675,28212,14335,2609,2723,8545,54158,26041,7086,6918,14113,56730,27944,5792,5904,17090,25949,12311,3280,3268,7090,27840,13635,2558,2762,8885,28209,13730,3806,3650,7023,28890,14309,3234,3142,8206,49792,24288,6490,6227,12787,55621,27121,6807,6395,15297,24217,11587,3145,3059,6426,27337,13262,3041,3058,7976,25575,12701,3345,3168,6361,28285,13860,3766,3337,7322,46709,23097,5681,6242,11689,56388,27116,7242,7224,14805,22635,10941,2716,3013,5965,27226,12895,3367,3485,7479,24074,12156,2965,3229,5724,29162,14221,3875,3739,7326,44418,22025,5529,6398,10466,50526,24560,6562,6357,13046,21535,10531,2571,3133,5300,24573,11662,3195,3124,6592,22883,11494,2958,3265,5166,25953,12898,3367,3233,6454,35681,17689,4960,5422,7610,47077,23093,5663,6483,11838,17116,8473,2206,2582,3855,22563,10774,2684,3104,6001,18565,9216,2754,2840,3755,24514,12319,2979,3379,5837,41885,20090,6337,6775,8683,44252,21642,5598,6729,10284,19429,9237,2766,3211,4215,20966,10168,2530,3200,5068,22456,10853,3571,3564,4468,23286,11474,3068,3529,5216,33087,15658,5560,5431,6438,34168,16583,4853,5447,7284,14602,6847,2328,2524,2903,15764,7608,2094,2534,3529,18485,8811,3232,2907,3535,18403,8975,2760,2913,3755,24891,11252,4689,4318,4632,37086,17472,5672,6328,7614,10063,4417,1838,1886,1922,15992,7433,2327,2866,3366,14828,6835,2851,2432,2710,21093,10038,3346,3462,4247,17048,7543,3257,3041,3207,26180,11985,4481,4588,5127,6059,2540,1171,1197,1151,10211,4627,1646,1944,1994,10989,5003,2086,1844,2056,15970,7359,2835,2644,3133,9488,4063,1757,1837,1831,15409,6532,2900,2969,3008,3049,1331,570,627,521,5141,2122,971,1078,970,6439,2732,1187,1210,1310,10268,4410,1929,1890,2038,3167,1350,624,673,520,6571,2733,1279,1310,1250,959,405,214,209,131,1829,682,383,419,346,2596,1111,482,542,461,4742,2051,896,891,904,783,358,165,156,104,1699,650,334,366,349,174,69,46,42,17,435,176,94,90,75,609,289,119,114,87,1264,474,241,275,274,83,35,19,10,19,235,84,46,50,54,22,7,5,1,9,39,14,13,5,7,61,28,14,9,10,196,70,33,46,47,172017,71470,15074,17219,68254,180546,76593,16473,17481,69999,80214,33060,6985,8056,32113,84109,35227,7718,8220,32943,91803,38410,8089,9163,36141,96437,41365,8756,9261,37056,1612,522,266,242,582,1732,645,257,249,581,824,269,133,115,307,912,341,141,125,305,788,253,133,127,275,820,305,116,124,276,2308,813,320,324,851,2306,848,340,324,794,1181,422,168,168,423,1185,430,177,167,410,1127,391,152,156,428,1121,417,163,156,384,3202,1104,456,390,1252,2472,912,346,334,880,1622,558,230,196,638,1255,466,170,166,452,1580,546,226,194,614,1217,446,176,167,428,4648,1707,637,452,1852,2841,1057,380,390,1015,2338,836,326,218,958,1463,536,195,213,519,2310,871,311,234,894,1378,521,185,177,495,7123,2539,959,815,2810,3918,1494,541,480,1404,3481,1185,502,392,1402,1934,723,276,243,692,3642,1354,457,423,1408,1985,771,265,237,712,8925,3540,1042,934,3409,6761,2811,859,675,2415,4213,1636,477,431,1669,3246,1281,437,328,1201,4712,1904,565,503,1740,3515,1530,423,348,1215,11458,4998,1215,1099,4146,11647,4902,1459,1113,4173,5297,2312,535,506,1944,5549,2280,737,528,2005,6161,2686,680,593,2202,6097,2622,722,585,2168,13989,6387,1293,1351,4958,14114,6070,1573,1301,5169,6502,2924,596,621,2361,6728,2790,752,609,2578,7487,3463,697,730,2597,7385,3280,822,692,2591,15662,6864,1328,1578,5892,14639,6650,1454,1285,5250,7283,3252,632,712,2687,7029,3178,659,621,2570,8379,3612,696,866,3205,7611,3472,795,664,2680,16665,7089,1233,1603,6740,15423,7123,1448,1413,5440,7838,3283,590,788,3177,7303,3327,703,647,2627,8827,3806,643,815,3563,8120,3796,745,766,2813,17236,7202,1088,1529,7417,16186,7164,1340,1569,6112,8451,3476,523,737,3715,7597,3413,636,728,2821,8785,3726,565,792,3702,8589,3752,704,841,3291,15844,6631,977,1430,6806,16713,7148,1289,1607,6669,7845,3222,483,689,3451,7855,3323,619,786,3127,7999,3409,494,741,3355,8858,3825,670,821,3542,11867,4971,798,1160,4938,17003,7101,1096,1524,7282,5845,2443,348,592,2462,8224,3380,522,725,3598,6022,2528,450,568,2476,8778,3722,573,799,3685,13161,5574,1017,1295,5275,15483,6459,979,1397,6648,6217,2603,472,650,2492,7539,3106,471,669,3293,6944,2971,545,645,2783,7944,3353,508,728,3355,10285,4170,883,1124,4108,11235,4726,803,1051,4655,4600,1875,383,518,1824,5332,2216,336,521,2259,5685,2295,500,606,2284,5902,2510,467,529,2396,7969,3148,702,843,3276,11858,5053,928,1119,4758,3250,1288,288,367,1307,5188,2170,409,526,2084,4719,1860,414,476,1969,6670,2883,519,593,2674,5349,2221,462,561,2105,8302,3321,696,864,3421,1921,802,176,194,749,3255,1298,261,355,1341,3428,1419,286,367,1356,5046,2023,435,509,2081,3204,1356,289,331,1228,5098,2007,442,483,2167,1064,479,94,112,379,1739,666,146,187,741,2140,877,195,219,849,3359,1341,296,296,1426,1077,454,81,114,428,2134,838,189,229,878,368,161,26,40,141,596,232,59,62,244,829,344,64,85,336,1538,606,130,167,635,283,120,17,28,118,598,244,44,60,250,72,33,2,10,27,153,66,12,11,64,211,87,15,18,91,445,178,32,49,186,30,9,2,5,14,84,21,10,14,39,2,1,1,0,0,26,7,2,4,14,28,8,1,5,14,58,15,8,10,25,122825,49780,18863,16110,38072,143757,59562,22097,18088,44010,59608,24359,8992,7657,18600,70595,29459,10754,8599,21783,63217,25421,9871,8453,19472,73162,30103,11343,9489,22227,1738,676,226,286,550,2708,1162,379,363,803,895,337,119,147,292,1395,630,182,180,404,843,339,107,139,258,1312,533,197,183,399,2601,1013,341,415,832,4454,1849,524,606,1476,1305,504,170,214,417,2265,907,305,302,752,1296,509,171,201,415,2189,942,219,304,724,3829,1439,548,597,1245,3961,1572,502,529,1359,1941,711,302,306,622,2044,788,270,272,714,1888,728,246,291,623,1917,784,232,257,645,5432,2126,899,849,1558,3747,1500,513,545,1189,2799,1122,455,438,784,1885,723,278,278,606,2633,1004,444,411,774,1862,778,234,268,583,9395,3602,1746,1460,2587,4903,1917,734,717,1535,4704,1759,897,705,1343,2337,890,369,331,748,4691,1843,849,755,1244,2565,1027,365,386,788,11663,4640,2120,1573,3330,7583,3184,1240,1055,2104,5621,2212,1017,765,1627,3582,1509,577,504,993,6042,2428,1103,808,1703,4001,1675,663,551,1112,12048,4991,2054,1580,3423,13181,5520,2308,1731,3622,5757,2398,937,741,1681,6462,2652,1160,827,1823,6291,2593,1117,839,1742,6719,2868,1148,904,1799,12182,5178,1881,1590,3533,15804,6590,2706,1849,4660,5829,2540,889,721,1679,7876,3319,1320,914,2323,6353,2638,992,869,1854,7928,3271,1386,935,2337,11575,4874,1709,1475,3517,14802,6290,2499,1773,4240,5613,2411,792,660,1750,7382,3139,1187,856,2200,5962,2463,917,815,1767,7420,3151,1312,917,2040,10061,4063,1460,1208,3330,13537,5848,2099,1703,3887,5070,2092,764,587,1627,6739,2983,1011,809,1935,4991,1971,696,621,1703,6798,2864,1088,894,1952,9263,3856,1201,1056,3150,12243,5216,1850,1495,3681,4817,2031,629,521,1636,6064,2645,899,653,1867,4446,1825,572,535,1514,6178,2571,951,842,1814,8016,3370,986,933,2727,10508,4272,1547,1269,3419,4120,1736,485,472,1427,5324,2236,800,614,1674,3896,1634,501,461,1300,5184,2036,747,655,1745,5987,2373,824,748,2042,9503,3953,1287,1115,3148,3061,1218,399,388,1056,4987,2103,694,545,1645,2926,1155,425,360,986,4515,1849,593,570,1503,5949,2397,832,715,2005,8212,3412,1075,1009,2716,2920,1195,365,330,1030,4278,1761,554,515,1449,3029,1202,467,385,975,3934,1652,521,494,1267,4897,1964,758,626,1549,5856,2271,869,733,1983,2176,876,309,297,694,2903,1125,417,372,989,2721,1088,449,329,855,2953,1145,453,361,994,3652,1449,578,449,1176,5398,2161,800,647,1791,1493,611,237,182,463,2524,1019,342,289,874,2159,838,341,267,713,2874,1142,458,358,917,2554,989,397,312,856,3786,1496,597,484,1209,901,366,139,110,286,1477,609,219,196,453,1653,623,258,202,570,2309,887,378,288,756,1341,542,216,146,437,2314,876,373,306,759,431,182,61,47,141,769,298,127,108,236,910,360,155,99,296,1545,578,246,198,524,451,170,59,64,158,979,366,150,132,330,129,46,21,22,40,249,102,38,29,80,375,144,49,49,133,730,264,112,103,250,123,45,12,17,49,244,94,41,27,83,23,11,3,4,5,44,17,5,6,16,100,34,9,13,44,200,77,36,21,66,15,3,5,4,3,35,15,6,null,15,3,1,2,0,0,7,4,1,null,2,12,2,3,4,3,28,11,5,null,13,114114,42120,9913,23165,38916,213145,82727,22138,34318,73962,53577,19788,4521,11017,18251,103726,39430,10920,16715,36660,60537,22332,5392,12148,20665,109419,43297,11218,17602,37302,2128,898,133,379,718,1811,754,177,207,672,1087,445,69,195,378,920,396,84,94,347,1041,453,64,184,340,891,359,93,114,325,4649,1983,302,871,1493,5901,2515,673,699,2015,2455,1069,156,473,757,2856,1197,304,349,1007,2194,914,146,398,736,3045,1318,369,350,1008,6595,2637,486,1419,2053,9329,3878,1063,1253,3135,3332,1341,248,702,1041,4832,2009,550,642,1631,3263,1296,238,717,1012,4497,1869,513,611,1504,8146,3090,654,1835,2567,11722,4840,1226,1720,3936,4152,1566,317,948,1321,6044,2520,636,874,2014,3994,1524,337,887,1246,5678,2321,589,846,1922,12196,4651,971,2640,3934,15844,6459,1691,2650,5043,5839,2206,463,1293,1877,7794,3130,843,1306,2515,6357,2445,508,1347,2057,8050,3329,848,1343,2528,18926,7379,1601,3813,6133,21722,8615,2463,3517,7127,9025,3569,719,1842,2895,10410,4003,1240,1710,3457,9901,3810,882,1971,3238,11312,4612,1223,1807,3670,17794,7124,1481,3313,5876,27532,10898,3041,4241,9353,8364,3316,709,1528,2811,13446,5166,1595,2093,4592,9430,3808,772,1785,3065,14086,5732,1445,2148,4761,13557,5079,1126,2532,4820,32114,12795,3185,5046,11089,6220,2282,498,1120,2320,16036,6252,1656,2532,5597,7337,2797,628,1412,2500,16079,6543,1529,2514,5492,9024,3200,696,1663,3465,27933,11143,2752,4538,9500,4102,1425,295,764,1618,13911,5379,1382,2270,4880,4922,1775,401,899,1847,14023,5764,1370,2269,4620,5032,1611,437,981,2003,20883,7923,2000,3447,7512,2272,756,193,441,882,10081,3699,911,1616,3854,2760,855,244,540,1121,10802,4223,1089,1831,3658,3145,958,224,630,1333,13785,5042,1248,2287,5209,1374,387,100,297,590,6672,2348,591,1098,2636,1771,571,124,333,743,7113,2694,657,1190,2573,2318,768,169,463,918,8048,2729,780,1411,3128,1040,344,84,210,402,3784,1258,366,655,1505,1278,424,85,253,516,4264,1472,413,756,1623,1834,529,117,435,753,5064,1656,443,917,2048,845,226,60,213,346,2276,683,195,454,944,989,303,57,222,407,2788,973,248,464,1104,1696,491,150,423,632,3445,1201,288,651,1305,714,213,60,198,243,1515,515,139,290,572,982,278,90,225,389,1931,686,150,362,733,2473,627,458,627,761,2414,743,188,496,988,1065,261,188,301,315,1098,314,88,238,459,1408,366,270,326,446,1316,429,100,258,529,2115,497,462,523,633,1741,575,157,361,647,859,201,193,237,228,700,229,61,161,249,1256,296,269,286,405,1041,346,96,200,398,1263,311,236,345,371,1987,515,392,450,629,471,100,92,159,120,759,194,154,178,233,792,211,144,186,251,1228,321,238,272,396,878,212,161,190,315,1241,293,264,285,399,286,67,63,76,80,421,100,95,104,122,592,145,98,114,235,821,193,169,182,277,251,54,39,63,95,449,112,80,108,149,65,11,12,19,23,135,28,26,41,40,217,51,34,49,83,314,84,54,67,110,55,13,3,12,27,159,36,28,30,65,9,3,2,1,3,35,11,5,11,8,46,10,1,11,24,124,25,23,19,56,8,0,0,3,5,22,5,1,3,13,1,0,0,0,1,2,0,null,0,2,7,0,0,3,4,20,4,1,3,11], 9 | "id" : ["birth","age","gender","time","residence","concept"], 10 | "size" : [6,22,3,2,5,1], 11 | "role": { 12 | "time": ["time"], 13 | "geo": ["residence", "birth"], 14 | "metric": ["concept"] 15 | }, 16 | "dimension" : { 17 | "concept": { 18 | "label" : "concept", 19 | "category" : { 20 | "label" : { 21 | "pop" : "population" 22 | }, 23 | "unit" : { 24 | "pop" : { 25 | "label" : "persons", 26 | "decimals" : 0 27 | } 28 | } 29 | } 30 | }, 31 | "birth" : { 32 | "label" : "place of birth", 33 | "category" : { 34 | "index" : ["T", "C", "P", "G", "A", "F"], 35 | "label" : { 36 | "T" : "total", 37 | "C" : "county of residence", 38 | "P" : "another county in the same province", 39 | "G" : "another province of Galicia", 40 | "A" : "in another autonomous community", 41 | "F" : "abroad" 42 | } 43 | } 44 | } 45 | , 46 | "age" : { 47 | "label" : "age group", 48 | "category" : { 49 | "index" : [ 50 | "T", "0", "5", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "65", "70", "75", 51 | "80", "85", "90", "95", "100" 52 | ], 53 | "label" : { 54 | "T" : "total", 55 | "0" : "0-4", 56 | "5" : "5-9", 57 | "10" : "10-14", 58 | "15" : "15-19", 59 | "20" : "20-24", 60 | "25" : "25-29", 61 | "30" : "30-34", 62 | "35" : "35-39", 63 | "40" : "40-44", 64 | "45" : "45-49", 65 | "50" : "50-54", 66 | "55" : "55-59", 67 | "60" : "60-64", 68 | "65" : "65-69", 69 | "70" : "70-74", 70 | "75" : "75-79", 71 | "80" : "80-84", 72 | "85" : "85-89", 73 | "90" : "90-94", 74 | "95" : "95-99", 75 | "100" : "100+" 76 | } 77 | } 78 | } 79 | , 80 | "gender" : { 81 | "label" : "gender", 82 | "category" : { 83 | "index" : ["T", "M", "F"], 84 | "label" : { 85 | "T" : "total", 86 | "M" : "male", 87 | "F" : "female" 88 | } 89 | } 90 | } 91 | , 92 | "time" : { 93 | "label" : "year", 94 | "category" : { 95 | "index" : { 96 | "2001" : 0, 97 | "2011" : 1 98 | } 99 | } 100 | } 101 | , 102 | "residence" : { 103 | "label" : "province of residence", 104 | "category" : { 105 | "index" : ["T", "15", "27", "32", "36"], 106 | "label" : { 107 | "T" : "total", 108 | "15" : "A Coruña", 109 | "27" : "Lugo", 110 | "32" : "Ourense", 111 | "36" : "Pontevedra" 112 | } 113 | } 114 | } 115 | }, 116 | "link" : { 117 | "alternate" : [ 118 | { 119 | "type" : "text/csv", 120 | "href" : "https://json-stat.org/samples/galicia.csv" 121 | } 122 | ] 123 | } 124 | } --------------------------------------------------------------------------------