0

I'm using R and I have a webpage that wants JSON formatted data to return what I want. However, when I set up a JSON object and paste it to my URL, R adds escape chars (backslash) to the double quotes in the JSON object. And I want to remove the backslashes:

R> library(jsonlite)
R> lst <- list(key = 'value')
R> json <- toJSON(lst)
R> url <- paste0('http://some.url.com?data=', json)

R> url
[1] "http://some.url.com?data={\"key\":[\"value\"]}"

My sessionInfo()

R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.0
LAPACK: /usr/lib/lapack/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_US.UTF-8          LC_NUMERIC=C                 
 [3] LC_TIME=en_US.UTF-8           LC_COLLATE=en_US.UTF-8       
 [5] LC_MONETARY=sv_SE.UTF-8       LC_MESSAGES=en_US.UTF-8      
 [7] LC_PAPER=sv_SE.UTF-8          LC_NAME=sv_SE.UTF-8          
 [9] LC_ADDRESS=sv_SE.UTF-8        LC_TELEPHONE=sv_SE.UTF-8     
[11] LC_MEASUREMENT=sv_SE.UTF-8    LC_IDENTIFICATION=sv_SE.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] XML_3.98-1.9 jsonlite_1.5 httr_1.3.1   rj_2.1.0-13 

loaded via a namespace (and not attached):
[1] compiler_3.4.2 R6_2.2.2       tools_3.4.2    rj.gd_2.1.0-2 
habana
  • 317
  • 1
  • 11
  • 2
    The slashes aren't really there. They only shows up in the console because R needs to escape them because it's print quotes between quotes. Use `cat(url)` to see what the string really looks like. – MrFlick Feb 13 '18 at 16:26
  • Ah. Ok... I'll ignore the bacslash and try the url. Thanx for super fast answer! – habana Feb 13 '18 at 16:31

0 Answers0