Need newlines in json output from Java String

Desired JSON output:
{"key":"value1  
           value2
           value3"}  

In Java,
String s = "value1 \\n value2 \\n value3"

but the output is just {"key":"value1 \\n value2 \\n value3"}
I have tried \n, \\n, \\\n, \\\\n and none worked.
renisenbeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
this :
{"key":"value1  
           value2
           value3"}  
is :
{"key":"value1\n\tvalue2\n\tvalue3"}  
So :
String s = "value1\n\tvalue2\n\tvalue3" ;
0
renisenbeAuthor Commented:
The Json output just prints out the \n\t with the rest of the output. I guess having a newline inside the json value is not a good idea.
0
girionisCommented:
Try this:

		char c = 0x000A;
		String s = "value1 " + c + " value2 " + c + " value3";

Open in new window


By the way why do you need new lines in the JSON string?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

renisenbeAuthor Commented:
Because my value1 string is really long. I'm thinking, i might need to make value1, value2 and value3 be elements in an array, not sure how.
0
girionisCommented:
Why don't you pass an array of strings then?

{ "key" : ["value1", "value2", "value3"] }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
girionisCommented:
Any reason why the value of my answer was "low"? Both my comments are perfectly valid answers.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.