09-04-2024 11:29 PM
Can anyone assist in getting my JSON structure from within a Javascript snippet to be a useable list to iterate through? no matter how I try to 'return' an object or array in the Javascript snippet step, there is no data structure to use in subsequent steps. I am just using a test situation after trying in vain with my actual recipe, and even a simple JSON array makes no difference.
Workato documentation is woefully lacking so I have no idea how to assign things to the output variables, I only have experience using the 'return' function. I have taken screenshots but can't seem to upload them to this message either, sorry!
Thanks in advance
Nick
11-16-2024 07:35 PM
Here's an example of a simple JavaScript snippet that returns a JSON array:
// Define your data as an array of JSON objects
let items = [
{ id: 1, name: "Item 1" },
{ id: 2, name: "Item 2" },
{ id: 3, name: "Item 3" }
];
// Return the array
return items;
11-16-2024 07:35 PM
If you're working with a stringified JSON and need to parse it, you can do:
// Example of stringified JSON input
let input = '[{"id": 1, "name": "Item 1"}, {"id": 2, "name": "Item 2"}]';
// Parse the string to JSON
let parsedData = JSON.parse(input);
// Return parsed data
return parsedData;