- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2023 04:03 AM - edited 01-27-2023 04:40 AM
Hi,
We are writing the below code in a flow designer action - Error: Unexpected token in object literal,Detail: Unexpected token in object literal. Why are we getting this error?
(function execute(inputs, outputs) {
// ... code ...
var nameValues = JSON.stringify(inputs.Additionalfields);
var obj;
nameValues = JSON.parse(JSON.parse(nameValues));
var encodedQuery = '';
gs.info('ain_sud_spoke1 ' + typeof nameValues);
var keys = (Object.keys(nameValues));
for(var i=0; i<keys.length-1; i++){
encodedQuery += '' + keys[i] + '=' + nameValues[keys[i]] + '^';
}
encodedQuery += '' + keys[i] + '=' + nameValues[keys[i]];
outputs.encoded_query = encodedQuery;
})(inputs, outputs);
We are using this particular action in a flow in flow designer for the 'Update Issue' action in JIRA spoke.
Regards,
Sudhangshu
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2023 02:48 AM - edited 01-29-2023 02:49 AM
Hi @sd2097 ,
The error message "Unexpected token in object literal" is indicating that there is a syntax issue in the code that you provided. This error is usually caused by a missing comma, a missing bracket, or a missing quotation mark.
It looks like the error is in this line: nameValues = JSON.parse(JSON.parse(nameValues));
It appears that the code is trying to parse the same JSON string twice, which is causing the error.
It seems that you are trying to parse the string into an object, and then again parsing it back into a string, which is not necessary and causing the error. You should try removing one of the JSON.parse() calls and see if that resolves the issue.
Also, you can check the type of 'inputs.Additionalfields' and see if it is already a json object or string before parsing it.
Regards,
Shravan
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2023 02:48 AM - edited 01-29-2023 02:49 AM
Hi @sd2097 ,
The error message "Unexpected token in object literal" is indicating that there is a syntax issue in the code that you provided. This error is usually caused by a missing comma, a missing bracket, or a missing quotation mark.
It looks like the error is in this line: nameValues = JSON.parse(JSON.parse(nameValues));
It appears that the code is trying to parse the same JSON string twice, which is causing the error.
It seems that you are trying to parse the string into an object, and then again parsing it back into a string, which is not necessary and causing the error. You should try removing one of the JSON.parse() calls and see if that resolves the issue.
Also, you can check the type of 'inputs.Additionalfields' and see if it is already a json object or string before parsing it.
Regards,
Shravan
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2023 10:23 PM
Hi Shravan,
We tried removing one of the JSON.parse() calls, and the action got executed. Thank you so much for your help.
Regards,
Sudhangshu