In rest message getting {"detail":"JSON parse error - Invalid \\escape: line 11 column 31 (char 359)\nPossible cause: trailing comma."}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 07:15 AM
Hi,
I am getting {"detail":"JSON parse error - Invalid \\escape: line 11 column 31 (char 359)\nPossible cause: trailing comma."}
error while passing value in rest message.
Workflow script:
var i = new GlideAggregate('sys_user');
var m = '';
var x = mr();
var j = '';
var x = current.variable_pool.select_users_groups.getDisplayValue();
if (x == 'Group') {
j = current.variables.please_enter_the_dl_group_name.u_cn.getDisplayValue();
} else {
j = names();
}
function names() {
var j = [];
var i = new GlideRecord('sys_user');
i.addQuery('sys_id', 'IN', current.variables.username);
i.query();
while (i.next()) {
j.push(i.email.toString());
}
return j;
}
function mr() {
var mrv;
var itemID = current.sys_id;
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(itemID)) {
mrv = ritmGR.variables.path;
// gs.addInfoMessage("a=" + mrv);
}
m = mrv.path_1;
}
var gr = new GlideRecord('sc_task');
gr.addEncodedQuery('short_descriptionSTARTSWITHNeed access to storage' +'^parent=' + current.sys_id);
gr.query();
if (gr.next()) {
var number = gr.number;
}
var instanceURL = gs.getProperty('glide.servlet.uri');
var callbackUrl = instanceURL + 'api/now/table/sc_task/' + gr.sys_id;
try {
var r = new sn_ws.RESTMessageV2('Ansible-NetworkShareAccess', 'NetworkShareAccess');
r.setStringParameterNoEscape('callbackUrl', callbackUrl);
r.setStringParameterNoEscape('ticketNumber',number);
r.setStringParameterNoEscape('sysId', gr.sys_id);
r.setStringParameterNoEscape('sn_sharePaths', m); // here getting error
r.setStringParameterNoEscape('sn_principalType', current.variable_pool.select_users_groups.getDisplayValue());
r.setStringParameterNoEscape('sn_principal', j);
r.setStringParameterNoEscape('sn_permissionType', current.variable_pool.please_select_the_type_of_access.getDisplayValue());
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
Like this I'm submitting value
Thanks,
Sowmya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 07:46 AM
Hi,
Whereever "m" is with your information:
r.setStringParameterNoEscape('sn_sharePaths', m); // here getting error
You'd want to concatenate (add) 2 more slashes to it, so something like:
var m = "\\" + variable_name_here;
For example.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 07:56 AM
The double backslash isn't the issue for the JSON (though it will be because whatever is receiving the info will see it as a single backslash), it's the "\a" in the middle of the line (line 11 column, 31). You need to escape all backslashes as "\\" to prevent the error. E.g., if the path was "\\file\new", the `\n` would get read as a newline.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 07:39 AM
While windows uses backslashes "\" for paths, it's an escape character in Javascript/JSON so you need to escape them to use them. Right now, column 31 is your `\a` and it's trying to read that as a special character that doesn't exist. The error isn't being thrown earlier because the `\\` at the beginning gets read as a single slash and not an escaped letter E.
Try submitting your path as: \\\\eaclab-fs1\\ansible_test
Note that each backslash needs to be escaped with another backslash, so you'll need four of them for the beginning of your network path.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 07:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-15-2022 07:53 AM
Yes. You just need to escape the value before sending it.
Either `JSON.stringify(m);` the value, or use a replace like `m.replace(/\\/g,'\\\\');`