Expand my Community achievements bar.

SOLVED

How to remove keys from a complex array

Avatar

Level 4

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:

tibormolnar_0-1761426638625.png

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!

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 2

@tibormolnar 

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.

Source : https://experienceleague.adobe.com/en/docs/workfront-fusion/using/create-scenarios/map-data/map-an-a...

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!

View solution in original post

2 Replies

Avatar

Correct answer by
Level 2

@tibormolnar 

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.

Source : https://experienceleague.adobe.com/en/docs/workfront-fusion/using/create-scenarios/map-data/map-an-a...

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!

Avatar

Employee

I suggest using the JSONata module in Fusion for this type of transformation. JSONata is designed specifically for reshaping and filtering JSON data structures.

 

Reference

 

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.