1

for the given object -

{
    "apiRequestType": "add",
    "noOfTIDsRequired": "1",
    "applicationId": "dxvfdv",
    "posId": "1140475",
    "midTidDetails": null
}

i get this -

"{\"apiRequestType\":\"add\",\"noOfTIDsRequired\":\"1\",\"applicationId\":\"dxvfdv\",\"posId\":\"1140475\",\"midTidDetails\":null}"

from -

objectMapper.writeValueAsString(inputMap))

but i want this -

"{    \"apiRequestType\": \"add\",    \"noOfTIDsRequired\": \"1\",    \"applicationId\": \"dxvfdv\",    \"posId\": \"1140475\",    \"midTidDetails\": null}"

can anyone suggest me how can I achieve my expected output using Jackson ObjectMapper. Or if any other library can be used then please suggest.

samar taj Shaikh
  • 1,165
  • 11
  • 18
  • 1
    Does this answer your question? [Convert JSON String to Pretty Print JSON output using Jackson](https://stackoverflow.com/questions/14515994/convert-json-string-to-pretty-print-json-output-using-jackson) – tgdavies Jul 26 '23 at 06:28
  • @tgdavies both top 2 answers given in your suggested link gives - "{\n \"apiRequestType\" : \"add\",\n \"noOfTIDsRequired\" : \"1\",\n \"applicationId\" : \"dxvfdv\",\n \"posId\" : \"1140475\",\n \"midTidDetails\" : null\n}" there is an extra \n with every key-value pair. Which is not what i was looking for. – samar taj Shaikh Jul 26 '23 at 06:33
  • Why do you want indents but not newlines? I assumed you were trying to make the JSON more human readable. – tgdavies Jul 26 '23 at 06:35
  • bro, if Newlines is what I have wanted, then I won't have put up a new question here on StackOverflow. Google search already suggested to me the link you shared. I exactly want what I have mentioned in the question. – samar taj Shaikh Jul 26 '23 at 07:07
  • Just remove the newlines from the string. – tgdavies Jul 26 '23 at 07:14
  • That is also not easy. in-between '\n' characters need to be replaced with ' ' but ending '\n' characters need to be replaced with ''. And I do not want to customize encryptino-decryption logic this much. – samar taj Shaikh Jul 26 '23 at 08:21

0 Answers0