How to convert input string to json string or json object in Springboot
I want below string to be converted into json of specified format.
String request = "xyz"
expected json output = "{"abc":{"efg":"request"}}".
Inner "request" in the above json should be "xyz".
CodePudding user response:
If there is no restriction about library, you can use below code block
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode node = objectMapper.createObjectNode();
JsonNode innerNode = objectMapper.createObjectNode();
((ObjectNode)innerNode).put("efg", request);
node.set("abc",innerNode);