R version 4.5.0 RC (2025-04-03 r88103 ucrt) -- "How About a Twenty-Six" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(RJSONIO) > jtxt = '[ 1, "abc", "xyz"]' > jdate = '[ 1, "/Date(1335746208)/", "xyz"]' > jnewdate = '[ 1, "/new Date(1335746208)/", "xyz"]' > > > > a = fromJSON(jtxt, stringFun = I(getNativeSymbolInfo("dummyStringOperation")$address)) > b = fromJSON(jtxt, stringFun = I(getNativeSymbolInfo("dummyStringOperation"))) > c = fromJSON(jtxt, stringFun = I("dummyStringOperation")) > d = fromJSON(jtxt, stringFun = structure("dummyStringOperation", class = "NativeStringRoutine")) > > e = fromJSON(jtxt, stringFun = I("dummyStringOperation"), simplify = TRUE) > > > ans = fromJSON(jtxt, stringFun = structure("R_json_dateStringOp", class = "SEXPRoutine")) > sapply(ans, class) == c("numeric", "character", "character") [1] TRUE TRUE TRUE > ans = fromJSON(jtxt, stringFun = "R_json_dateStringOp") > > ans = fromJSON(jtxt, stringFun = structure("R_json_dateStringOp", class = "SEXPRoutine"), simplify = TRUE) > > # process jdate > ans = fromJSON(jdate, stringFun = structure("R_json_dateStringOp", class = "SEXPRoutine")) > ans = fromJSON(jdate, stringFun = "R_json_dateStringOp") > > > # process strings by just returning them. > fromJSON(jtxt, stringFun = function(val) val) [[1]] [1] 1 [[2]] [1] "abc" [[3]] [1] "xyz" > > # process strings by prefixing them with xxx_ > fromJSON(jtxt, stringFun = function(val) sprintf("xxx_%s", val)) [[1]] [1] 1 [[2]] [1] "xxx_abc" [[3]] [1] "xxx_xyz" > > jtxt = '[ "1", "2.3", "3.1415"]' # all numeric but in "" > ans = fromJSON(jtxt) > stopifnot(is.character(ans)) > > # convert all of the strings to numeric! > ans = fromJSON(jtxt, stringFun = function(val) as.numeric(val)) > stopifnot(is.numeric(ans)) > > # Now convert them all to TRUE as logicals > ans = fromJSON(jtxt, stringFun = function(val) TRUE) > stopifnot(is.logical(ans)) > > > # > jtxt = '[ 1, "/new Date(12312313)", "/Date(12312313)"]' > ans = fromJSON(jtxt) > > ans = fromJSON(jtxt, stringFun = "R_json_dateStringOp", simplify = FALSE) > stopifnot(all(mapply(is, ans, c("numeric", "POSIXct", "POSIXct")))) > > > > proc.time() user system elapsed 0.15 0.04 0.18