RJSONIO: Serialize R objects to JSON, JavaScript Object Notation

RオブジェクトとJSONの取り扱い

> library(RJSONIO)

バージョン: 1.3.0


関数名 概略
JSON_T_ARRAY_BEGIN Symbolic constants identifying the type of a JSON value.
asJSVars Serialize R objects as Javsscript/ActionScript variables
basicJSONHandler Create handler for processing JSON elements from a parser
fromJSON Convert JSON content to R objects
isValidJSON Test if JSON content is valid
readJSONStream Read JSON from a Connection/Stream
toJSON Convert an R object to a string in Javascript Object Notation

basicJSONHandler

> h <- basicJSONHandler()
> x <- fromJSON("[1, 2, 3]", h)
> x
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3
> h$value()
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3

fromJSON

JSON形式の読み込み

ref) rjson::fromJSON(), jsonlite::fromJSON()

Arguments

  • content
  • handler
  • default.size
  • depth
  • allowComments
  • asText
  • data
  • maxChar
  • simplify
  • nullValue
  • simplifyWithNames
  • encoding
  • ...
  • stringFun
> fromJSON(I(toJSON(1:10)))
 [1]  1  2  3  4  5  6  7  8  9 10
> fromJSON('{"ok":true,"id":"x123","rev":"1-1794908527"}')
$ok
[1] TRUE

$id
[1] "x123"

$rev
[1] "1-1794908527"

isValidJSON

JSONが適切な構文であるかを評価する

ref) jsonlite::validate()

Arguments

  • content
  • asText
  • ...
> isValidJSON(content = I('{"foo" : "bar"}'))
[1] TRUE
> isValidJSON('{foo : "bar"}', TRUE)
[1] FALSE

readJSONStream

> readJSONStream(con, 
+                cb = NULL, 
+                simplify = Strict, 
+                nullValue = NULL,
+                simplifyWithNames = TRUE)

toJSON

ref) rjson::toJSON(), jsonlite::toJSON()

> toJSON(1:10)
[1] "[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]"
> toJSON(rnorm(3), digits = 4)
[1] "[ 0.2144, -0.3247, 0.09458 ]"