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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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" ;
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.
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?
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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.
girionisCommented:
Why don't you pass an array of strings then?

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

Open in new window

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.
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.