I'm in a need to obtain a data from the backend and it will be assigned to local variables through JSP in the front-end. The actual string data coming from backend is below:
"{\"deltas\":[{\"source\":{\"position\":63,\"lines\":[]},\"target\":{\"position\":65,\"lines\":[\"return {\"]},\"type\":\"INSERT\"},{\"source\":{\"position\":57,\"lines\":[\"//comment one\",\"//comment two\",\"//comment three\"]},\"target\":{\"position\":62,\"lines\":[]},\"type\":\"DELETE\"},{\"source\":{\"position\":53,\"lines\":[\"\"]},\"target\":{\"position\":56,\"lines\":[\"version.open(options,endpoint, false);\",\"version.send(payload);\",\"result \= version.responseE4X;\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":44,\"lines\":[]},\"target\":{\"position\":44,\"lines\":[\" \\\"\<sch:status\>\\\" status \\\"\</sch:status\>\\\" \",\" \\\"\<sch:workflowExternalRef\>\\\" refId \\\"\</sch:workflowExternalRef\>\\\" \",\" \\\"\<sch:description\>\\\" description \\\"\</sch:description\>\\\" \"]},\"type\":\"INSERT\"},{\"source\":{\"position\":42,\"lines\":[\"} else if(taskType\=\=\\\"registration\\\"){\"]},\"target\":{\"position\":42,\"lines\":[\"} else if(taskType\=\=\\\"appRegistration\\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":35,\"lines\":[\"} else if(taskType\=\=\\\"app\\\"){\"]},\"target\":{\"position\":35,\"lines\":[\"} else if(taskType\=\=\\\"application\\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":28,\"lines\":[\"} else if(taskType\=\=\\\"signup\\\"){\"]},\"target\":{\"position\":28,\"lines\":[\"} else if(taskType\=\=\\\"user-signup\\\"){\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":14,\"lines\":[\" { name : \\\"\\\", value :cookie },\"]},\"target\":{\"position\":14,\"lines\":[\" { name : \\\"Cookie\\\", value :cookie },\"]},\"type\":\"CHANGE\"},{\"source\":{\"position\":11,\"lines\":[\"var cookie\=session.get(\\\"\\\");\"]},\"target\":{\"position\":11,\"lines\":[\"var cookie\=session.get(\\\"workflowCookie\\\");\"]},\"type\":\"CHANGE\"}]}"
I'm using JSP to assign it to a local variable as below:
var diffOutputList = '<c:out value="${diffResponse.diffOutputList}"/>'
After this when I'm printing the diffOutputList in the console, it is printing like below:
{"deltas":[{"source":{"position":63,"lines":[]},"target":{"position":65,"lines":["return {"]},"type":"INSERT"},{"source":{"position":57,"lines":["//comment one","//comment two","//comment three"]},"target":{"position":62,"lines":[]},"type":"DELETE"},{"source":{"position":53,"lines":[""]},"target":{"position":56,"lines":["version.open(options,endpoint, false);","version.send(payload);","result = version.responseE4X;"]},"type":"CHANGE"},{"source":{"position":44,"lines":[]},"target":{"position":44,"lines":[" "<sch:status>" status "</sch:status>" "," "<sch:workflowExternalRef>" refId "</sch:workflowExternalRef>" "," "<sch:description>" description "</sch:description>" "]},"type":"INSERT"},{"source":{"position":42,"lines":["} else if(taskType=="registration"){"]},"target":{"position":42,"lines":["} else if(taskType=="appRegistration"){"]},"type":"CHANGE"},{"source":{"position":35,"lines":["} else if(taskType=="app"){"]},"target":{"position":35,"lines":["} else if(taskType=="application"){"]},"type":"CHANGE"},{"source":{"position":28,"lines":["} else if(taskType=="signup"){"]},"target":{"position":28,"lines":["} else if(taskType=="user-signup"){"]},"type":"CHANGE"},{"source":{"position":14,"lines":[" { name : "", value :cookie },"]},"target":{"position":14,"lines":[" { name : "Cookie", value :cookie },"]},"type":"CHANGE"},{"source":{"position":11,"lines":["var cookie=session.get("");"]},"target":{"position":11,"lines":["var cookie=session.get("workflowCookie");"]},"type":"CHANGE"}]}
But I need the string in the below format:
'{"deltas":[{"source":{"position":63,"lines":[]},"target":{"position":65,"lines":["return {"]},"type":"INSERT"},{"source":{"position":57,"lines":["//comment one","//comment two","//comment three"]},"target":{"position":62,"lines":[]},"type":"DELETE"},{"source":{"position":53,"lines":[""]},"target":{"position":56,"lines":["version.open(options,endpoint, false);","version.send(payload);","result = version.responseE4X;"]},"type":"CHANGE"},{"source":{"position":44,"lines":[]},"target":{"position":44,"lines":[" \\"<sch:status>\\" status \\"</sch:status>\\" "," \\"<sch:workflowExternalRef>\\" refId \\"</sch:workflowExternalRef>\\" "," \\"<sch:description>\\" description \\"</sch:description>\\" "]},"type":"INSERT"},{"source":{"position":42,"lines":["} else if(taskType==\\"registration\\"){"]},"target":{"position":42,"lines":["} else if(taskType==\\"appRegistration\\"){"]},"type":"CHANGE"},{"source":{"position":35,"lines":["} else if(taskType==\\"app\\"){"]},"target":{"position":35,"lines":["} else if(taskType==\\"application\\"){"]},"type":"CHANGE"},{"source":{"position":28,"lines":["} else if(taskType==\\"signup\\"){"]},"target":{"position":28,"lines":["} else if(taskType==\\"user-signup\\"){"]},"type":"CHANGE"},{"source":{"position":14,"lines":[" { name : \\"\\", value :cookie },"]},"target":{"position":14,"lines":[" { name : \\"Cookie\\", value :cookie },"]},"type":"CHANGE"},{"source":{"position":11,"lines":["var cookie=session.get(\\"\\");"]},"target":{"position":11,"lines":["var cookie=session.get(\\"workflowCookie\\");"]},"type":"CHANGE"}]}'
CodePudding user response:
c:out
automatically escapes XML tags in the rendering. The escaping replaces "
by "
.
You can disable the escaping with the escapeXml
parameter:
var diffOutputList = '<c:out escapeXml="false" value="${diffResponse.diffOutputList}" />'
But in this case, c:out
is not really necessary, you could use:
var diffOutputList = '${diffResponse.diffOutputList}'