What is the correct way to build JSON strings in Java so you don't get extra slash characters in result? What is the correct way to build JSON strings in Java so you don't get extra slash characters in result? json json

What is the correct way to build JSON strings in Java so you don't get extra slash characters in result?


Personally I always use GSON when dealing with JSON in java.

You are right your problem has to do with nesting JSON, you add a string that contains " to messages, it escapes those because it thinks you want the literal string like that. It doesn't know that it's also a object.

Have you tried just doing this?

replyObj.put("messages", messages);