I want to put a \n
(Line Separator) between the variable string values. So the data shows like:
test
test1
test2
test3
How do I acplish this following JSON practices?
My example:
data: JSON.stringify({
"sessionID":xxxxx,
"synchronize":false,
"sourceRequest":{
"numberOrigin":xxxxxx,
"type":"x",
"description":test + "\\n" + test2 "\\n" + test3 "\\n" + test4,
"userID":xxxxxxxx,
"contact":{
"name":"xxxxxxxxxxxxxxxxx",
"phoneNumber":"xxxxxxxxxx",
"email":xxxx,
"department":"xxxxx"
},
I want to put a \n
(Line Separator) between the variable string values. So the data shows like:
test
test1
test2
test3
How do I acplish this following JSON practices?
My example:
data: JSON.stringify({
"sessionID":xxxxx,
"synchronize":false,
"sourceRequest":{
"numberOrigin":xxxxxx,
"type":"x",
"description":test + "\\n" + test2 "\\n" + test3 "\\n" + test4,
"userID":xxxxxxxx,
"contact":{
"name":"xxxxxxxxxxxxxxxxx",
"phoneNumber":"xxxxxxxxxx",
"email":xxxx,
"department":"xxxxx"
},
Share
Improve this question
edited Mar 8, 2024 at 16:57
Sayuri Mizuguchi
asked Dec 15, 2016 at 18:10
Sayuri MizuguchiSayuri Mizuguchi
5,3303 gold badges29 silver badges57 bronze badges
2
-
Some plus signs seem missing. Did you mean
test + "\\n" + test2 + "\\n" + test3 + "\\n" + test4
? – Cœur Commented Dec 15, 2016 at 18:18 - What is the issue now ? – Rajshekar Reddy Commented Dec 15, 2016 at 18:18
2 Answers
Reset to default 5The "\\n"
says to put a literal \n
in the string - 2 chars. You should just use "\n"
to say that its a new line - 1 char.
Note if viewing in Windows Notepad, \n
is not enough for a new line.
A simple ' ' (space character) is enough to do what is needed, the json key does hold a string after all, if you need something more prominent you can use '\t', refer here for more.