Error: Unexpected token in object literal,Detail: Unexpected token in object in Flow Designer action

sd2097
Tera Guru

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

1 ACCEPTED SOLUTION

Sai Shravan
Mega Sage

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

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

2 REPLIES 2

Sai Shravan
Mega Sage

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

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

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