If I have an array of collections with key-value pairs, what's the easiest way to transform this array so that only certain keys (and their values) are preserved in the array?
For example, if this is the output of a HTTP request module:
how can I transform this data so that within each collection I have only the value and label keys?
I'd like to store the transformed array in a variable so that I can later "search" within that with the map function.
Thank you!
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Based on my understanding, you want label & value from collection and create a new simplified array.
You can achieve this by mapping items into a new array & using map function.
This will help you define exactly which fields you want to include in your new array structure.
If this helps, please mark this as Correct answer so others can benefit too!
Based on my understanding, you want label & value from collection and create a new simplified array.
You can achieve this by mapping items into a new array & using map function.
This will help you define exactly which fields you want to include in your new array structure.
If this helps, please mark this as Correct answer so others can benefit too!
I suggest using the JSONata module in Fusion for this type of transformation. JSONata is designed specifically for reshaping and filtering JSON data structures.
For example, if your HTTP response contains an array under data, you can transform it into a simpler structure like the following:
data.{
"value": value,
"label": label
}
This will produce an array that contains only the value and label keys for each item. You can then store the transformed result in a variable and use it later with map, search, or other collection tools.
Additionally, large language models can help generate or refine JSONata expressions by providing a sample input and expected output.