How to Remove escape characters from javascript variable used inside script tag.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018 01:00 AM
i have a ui page in the html section of that ui page i am using an evaluate tag
<g:evaluate var="jvar_doc_content" object="true" expression="
var doc_content = JSON.stringify(new DocXDataProvider('08a81416db43134077d256d4ce9619b1').getDocumentJSON());
gs.info(doc_content);
doc_content;"
Now the variable - jvar_doc_content contains json value something like {"date":"2018-07-04 03:24:41","name":"xyz"}
The problem is that when i am using the variable inside jelly script tag(mentioned at last) the json is coming as
{\"date\":\"2018-07-04 03:24:41\",\"name\":\"xyz\"} instead of {"date":"2018-07-04 03:24:41","name":"xyz"}
Script tag
<script>
doc.setData(${jvar_doc_content});
</script>
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018 02:26 AM
replace(/[^\w\s]/gi, '') this is working but it replacing all the special character as well.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018 02:43 AM
can you try with this
replace(/\\/g, '');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018 03:45 AM
this doesnt work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018 04:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-05-2018 04:08 AM
i am adding the regex in below code before passing it to script tag
<g:evaluate var="jvar_doc_content" object="true" expression="
var doc_content = JSON.stringify(new DocXDataProvider('08a81416db43134077d256d4ce9619b1').getDocumentJSON());
doc_content.replace(/\\/g, '')
;"