Hello all,
I am having a problem reading a json string from command prompt in Windows using jsonlite
. All I want to do is pass in a json string as a command line argument into an R script. I am running my rscript as:
Rscript test-command-line-in-windows.R '{"name":"John","age":31,"city":"New York"}'
this returns the following error:
json_string contains:
'{name:John,age:31,city:New York}'
Error: lexical error: invalid char in json text.
'{name:John,age:31,city:New Yor
(right here) ------^
Execution halted
the file test-command-line-in-windows.R
has the following in it:
library(jsonlite)
args <- commandArgs(TRUE)
json_string <- args[1]
# see what is captured by commandArgs
cat("\njson_string contains:\n")
cat(json_string, "\n\n")
fromJSON(json_string)
It appears that Rscript in windows or just the command prompt in windows is removing all quotes.When I run this on Ubuntu everything works as expected.
Thanks for your help.