Question on JSON string value coming from Read Text file vs coming from JSON output from JavaScript Inject activity

Question the UiPath string value gurus out there. I’m working on getting JavaScript Inject output working so I can use Deserialize on it.

When I read in a JSON blob with the Read Text File activity and look at the value in the Studio debugger it looks like what is shown in the “Local Value” window in the image below:

The above is just example text purely looking to see how it looks and work with Deserialize. When I push this through Deserialize it works fine.

Side question, what does the @ sign in the Local Value window indicate/mean ?

When I use a small blob of JS code using the JS Inject activty which calls a URL and returns the result back into my workflow (which is JSON itself), the JSON string value looks this in the Studio Debugger:

Looking like this, Deserialize fails :frowning:

My question … Is there something I could be doing in the JS code itself to help make the returned value from the JS injection work or some quick replace or convert step in UiPath after the JS Inject activity to make this value looks-like and behave appropriately with the Deserilize activity ?

The JS code itself is simply this currently:

function(element,input)
{
    var theUrl = 'Encoded URL to hit';
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
    var jsonObj = JSON.parse(xmlHttp.responseText);
    //return xmlHttp.responseText;
    return JSON.stringify(jsonObj);
}

What I really needed from the above was a list of the “id” key values. Talked with a work buddy and came up with this which works perfectly.

function getOLIDs()
{
    var theUrl = "URL To hit";
	var xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
    xmlHttp.send( null );
	var webUrlJsonObj = JSON.parse(xmlHttp.responseText);
	// JSON return by URL for OrderLine has this structure:
	// { "data": <json array>, "totalRows": <number of array elements> }

	var jsonDataArray = webUrlJsonObj["data"];
	var jsonDataArraySize = webUrlJsonObj["totalRows"]
	var olIDArray = [];
	for(let i=0; i < jsonDataArraySize; i++) {
		var data = jsonDataArray[i];
		olIDArray.push(data["id"]);
	};
	return olIDArray;
}

Back in the workflow, I split(","c) into an array and loop away :slight_smile:

The final version will have a working argument to pass in a constructed URL to hit each time this JS is run.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.