- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 12:17 AM
Hi Team,
I got the result like below:
[{"title":"Students","link":"https:\/\/google.com\/wiki\/students\/"},{"title":"Control","link":"https:\/\/google.com\/wiki\/control\/"},{"title":"IQ- Engine","link":"https:\/\/google.com\/wiki\/iq-engine\/"}]
My requirement is how to load the flow designer outputs variables individually
Like.,
title : Students Link : https:\/\/google.com\/wiki\/students\/
title : Control, Link : https:\/\/google.com\/wiki\/control\/
title : IQ- Engine, Link : https:\/\/google.com\/wiki\/iq-engine\/
Help me on the same
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 06:45 AM
Hi @AnilM99, can you try below?
var response = '[{"title":"Students","link":"https://google.com/wiki/students/"},{"title":"Control","link":"https://google.com/wiki/control/"},{"title":"IQ-Engine","link":"https://google.com/wiki/iq-engine/"}]';
var parsedResponse = JSON.parse(response);
var firstObj = parsedResponse[0];
var secondObj = parsedResponse[1];
var thirdObj = parsedResponse[2];
Regards,
Sunil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 12:30 AM
Hey,
Strings can be transformed into a JSON object. This requires the use of the JSON.parse() function. The resulting object in your case will be an array of objects which you can iterate through:
var result = '[{"title":"Students","link":"https:\/\/google.com\/wiki\/students\/"},{"title":"Control","link":"https:\/\/google.com\/wiki\/control\/"},{"title":"IQ- Engine","link":"https:\/\/google.com\/wiki\/iq-engine\/"}]';
var resultObject = JSON.parse(result); // -> this transforms it into an object)
for(var i = 0; i<resultObject.length; i++){
gs.log(resultObject[i]); //-> this will show each of the objects in your array which will have the keys "title" and "link" with their respective values
}
Hope this helps
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 06:29 AM - edited 03-21-2024 06:30 AM
Hi @Fabian Thanks for the reply,
I tried the same script but i can't load 3 values in flow designer outputs variables, loaded only one value
Title : Students, Link : https:\/\/google.com\/wiki\/students\/
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 06:44 AM
Hi @Anil
You can have a custom action where you can have three output variables. Also with JSON.parse(), You can parse the result and assign to these output variables individually.
// Assuming 'result' contains the JSON result you provided
// Parse the JSON result
var data = JSON.parse(result);
// Loop through each item in the data array
data.forEach(function(item) {
// Extract title and link from each item
var title = item.title;
var link = item.link;
// Display the extracted data
console.log("Title: " + title + ", Link: " + link);
// You can also display this data in HTML or any other format as needed
});
Regards,
Alkshay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 06:45 AM
Hi @AnilM99, can you try below?
var response = '[{"title":"Students","link":"https://google.com/wiki/students/"},{"title":"Control","link":"https://google.com/wiki/control/"},{"title":"IQ-Engine","link":"https://google.com/wiki/iq-engine/"}]';
var parsedResponse = JSON.parse(response);
var firstObj = parsedResponse[0];
var secondObj = parsedResponse[1];
var thirdObj = parsedResponse[2];
Regards,
Sunil