How to transform objects to a flat list, and keep the unique values
This article explains how you change the following data structure:
"uniqueConfig": {
"color": {
"config": [
{
"color": "smokingblack matt"
},
{
"color": "smokingblack matt"
},
{
"color": "smokingblack matt"
},
{
"color": "blauw matt"
},
{
"color": "blauw matt"
},
{
"color": "blauw matt"
}
]
}
}
Into this structure:
"uniqueConfig": {
"color": {
"smokingblack matt": null,
"blue matt": null,
}
}
You'll need to select the setting "Chain multiple entity transformers".
In order to achieve the obtained result, you'll need the following Transformers being chained:
- Data, transform data using mappers and conditions
- Move using a pattern
- [Pattern] uniqueConfig.color.config
- [Replacement] uniqueConfig.color
- Move using a pattern
- Node, transform nodes
- [Accessor] Pattern accessor
- [Pattern] uniqueConfig.color.*
- [NodeTransformers] List mapper
- [Key accessor]
- [Mappers] List: Flip keys and values
- [Value Mapper]
- [Key accessor]
- [Mappers] Standard
- [From] String color
- [To] null
- [Accessor] Pattern accessor
- Data, transform data using mappers and conditions
- Move using a pattern
- [Pattern] uniqueConfig.color.*.*
- [Replacement] temp.color.$2
- Move using a pattern
- Data, transform data using mappers and conditions
- [Transformers] Move using a pattern
- [Pattern] temp.color.*
- [Replacement] result.uniqueConfig.color.$1
- [Transformers] Move using a pattern
The most important transformer in this example is the "List: Flip keys and values" transformer"
Screenshots
Transformer 1
Transformer 2
Transformer 3
Transformer 4