Error: Unexpected token in object literal,Detail: Unexpected token in object literal

Tomi Corigliano
Kilo Sage

Hi,

I'm trying to parse to json the result of a soap call as follows in an Action:

Step 3 in the action

(function execute(inputs, outputs) {
  	
    var treenodeOMS = JSON.parse(inputs.oms_response);
    gs.info('EC OMS Get Tree Node ID | ObjectType = ' + treenodeOMS.ObjectType);
	
})(inputs, outputs);

 But I'm getting the following error message:

TomiCorigliano_0-1702310222751.pngAnybody has a clue why I'm getting this error message?

 

Thanks in advance

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Tomi Corigliano From the screenshot, it is evident that the input variable 

inputs.oms_response

 

Contains &#13 ASCII code for Carriage Return, encoded as an XML character reference. Due to this, the JSON.parse method is crashing. Remove this XML character from string using string.replace method, and use JSON.parse to convert the JSON string to object.

 

Hope this helps.

 

 

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@Tomi Corigliano From the screenshot, it is evident that the input variable 

inputs.oms_response

 

Contains &#13 ASCII code for Carriage Return, encoded as an XML character reference. Due to this, the JSON.parse method is crashing. Remove this XML character from string using string.replace method, and use JSON.parse to convert the JSON string to object.

 

Hope this helps.

 

 

Thank you, I indeed had to do a replaceAll:

var response = inputs.oms_response.replaceAll('
','');