[R] how to avoid farword slashes in RJSONIO output

jim holtman jholtman at gmail.com
Sat Mar 31 15:58:56 CEST 2012


The forward slashes are to escape quotes and the new lines.  Here is
an example showing that when you output the file with 'cat' you
probably get the results you are expecting:


> x <- "({\"total\":5,\"results\":[\n {\n \"id\": 1,\n\"name\": \"Monkey D
+ Luffy\",\n\"position\": \"Captain\",\n\"ambition\": \"I Will become the
+ pirate king\" \n},\n{\n \"id\": 2,\n\"name\": \"Roronoa
+ zoro\",\n\"position\": \"Swordman\",\n\"ambition\": \"Become greatet
+ swordman\" \n},\n{\n \"id\": 3,\n\"name\": \"Sanji\",\n\"position\":
+ \"Cook\",\n\"ambition\": \"Find all blue\" \n},\n{\n \"id\": 4,\n\"name\":
+ \"Nami\",\n\"position\": \"Navigator\",\n\"ambition\": \"Draw map of the
+ world\" \n},\n{\n \"id\": 5,\n\"name\": \"Usopp\",\n\"position\":
+ \"Sniper\",\n\"ambition\": \"Become greatest warrior\" \n} \n]})"
> x
[1] "({\"total\":5,\"results\":[\n {\n \"id\": 1,\n\"name\": \"Monkey
D\nLuffy\",\n\"position\": \"Captain\",\n\"ambition\": \"I Will become
the\npirate king\" \n},\n{\n \"id\": 2,\n\"name\":
\"Roronoa\nzoro\",\n\"position\": \"Swordman\",\n\"ambition\":
\"Become greatet\nswordman\" \n},\n{\n \"id\": 3,\n\"name\":
\"Sanji\",\n\"position\":\n\"Cook\",\n\"ambition\": \"Find all blue\"
\n},\n{\n \"id\": 4,\n\"name\":\n\"Nami\",\n\"position\":
\"Navigator\",\n\"ambition\": \"Draw map of the\nworld\" \n},\n{\n
\"id\": 5,\n\"name\":
\"Usopp\",\n\"position\":\n\"Sniper\",\n\"ambition\": \"Become
greatest warrior\" \n} \n]})"
> cat(x)
({"total":5,"results":[
 {
 "id": 1,
"name": "Monkey D
Luffy",
"position": "Captain",
"ambition": "I Will become the
pirate king"
},
{
 "id": 2,
"name": "Roronoa
zoro",
"position": "Swordman",
"ambition": "Become greatet
swordman"
},
{
 "id": 3,
"name": "Sanji",
"position":
"Cook",
"ambition": "Find all blue"
},
{
 "id": 4,
"name":
"Nami",
"position": "Navigator",
"ambition": "Draw map of the
world"
},
{
 "id": 5,
"name": "Usopp",
"position":
"Sniper",
"ambition": "Become greatest warrior"
}
]})>




On Wed, Mar 28, 2012 at 9:36 AM, MLSC <mlscmahe at gmail.com> wrote:
> Hi All,
> I wanted know how to get RJSONIO output with out forward slashes? for
> example:
>
> "({\"total\":5,\"results\":[\n {\n \"id\": 1,\n\"name\": \"Monkey D
> Luffy\",\n\"position\": \"Captain\",\n\"ambition\": \"I Will become the
> pirate king\" \n},\n{\n \"id\": 2,\n\"name\": \"Roronoa
> zoro\",\n\"position\": \"Swordman\",\n\"ambition\": \"Become greatet
> swordman\" \n},\n{\n \"id\": 3,\n\"name\": \"Sanji\",\n\"position\":
> \"Cook\",\n\"ambition\": \"Find all blue\" \n},\n{\n \"id\": 4,\n\"name\":
> \"Nami\",\n\"position\": \"Navigator\",\n\"ambition\": \"Draw map of the
> world\" \n},\n{\n \"id\": 5,\n\"name\": \"Usopp\",\n\"position\":
> \"Sniper\",\n\"ambition\": \"Become greatest warrior\" \n} \n]})"
>
> Any help is appriciated.
>
> Regards,
> mlsc
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.



More information about the R-help mailing list