The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
JSON and R have similar but not identical type systems. This article
summarizes the common mappings used by fromJSON() and
toJSON().
#> JSON R
#> 1 object named list or simplified named vector
#> 2 array list or simplified vector/matrix
#> 3 string character
#> 4 number numeric
#> 5 true/false logical
#> 6 null NULL or the value supplied through nullValue
str(fromJSON('{"a": 1, "b": 2}', simplify = FALSE))
#> List of 2
#> $ a: num 1
#> $ b: num 2
str(fromJSON("[1, 2, 3]"))
#> num [1:3] 1 2 3
str(fromJSON('["a", "b", "c"]'))
#> chr [1:3] "a" "b" "c"
str(fromJSON("[true, false]"))
#> logi [1:2] TRUE FALSE
str(fromJSON("[1, null, 3]", nullValue = NA, simplify = TRUE))
#> num [1:3] 1 NA 3#> R JSON
#> 1 named list object
#> 2 unnamed list array
#> 3 atomic vector array
#> 4 named atomic vector object
#> 5 matrix nested array
#> 6 data.frame object by column, or array by row
#> 7 NA null
#> 8 NULL null
toJSON(list(a = 1, b = TRUE))
#> [1] "{\n \"a\": 1,\n\"b\": true \n}"
toJSON(list(1, TRUE, "x"))
#> [1] "[\n 1,\ntrue,\n\"x\" \n]"
toJSON(c(1, 2, 3))
#> [1] "[ 1, 2, 3 ]"
toJSON(c(a = 1, b = 2))
#> [1] "{\n \"a\": 1,\n\"b\": 2 \n}"
toJSON(matrix(1:4, nrow = 2))
#> [1] "[ [ 1, 3 ],\n[ 2, 4 ] ]"
toJSON(data.frame(a = 1:2, b = c("x", "y")))
#> [1] "{\n \"a\": [ 1, 2 ],\n\"b\": [ \"x\", \"y\" ] \n}"
toJSON(NA)
#> [1] "[ null ]"
toJSON(NULL)
#> [1] "[ null ] "Empty containers can carry different meaning depending on names.
The exported constants can be combined to control simplification.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.