Transform key value objects

How to transform a key value object into an array of objects

The example below shows an array of items. Each item contains a "product-id" key. It will be transformed into an array of objects. Each object has an "id" and "value" key based on the source data.

Source Result
Screenshot from 2020-10-09 09-41-06 Screenshot from 2020-10-09 09-45-30

 

 

Configure the transformer

Create a new transformer. Select the "Node, transform nodes" prototype. Pick the pattern accessor and enter the path to the items. In this example it is  "items.*". The node transformer will perform transform operations on each object in the array matched by the entered pattern.

New Project (5)

Then add a "Node Transformer". Select the "Move data between accessors" transformers. This transformer allows move data from one node into another in a new data structure.

Select the "Source accessor". Pick the "Pattern accessor". Enter a path the keys of the object that need to be transformed. In the example the pattern is "product-id".

Select the "Structrure accessor" as "Destination accessor". This will transform the key value object into the correct object structure.

Enter a "key". This determines the name that the new object key will get. It's value will be the original object key from the source data.

Enter a "value". This determines the name of the new object key that will contain the original value from the source data.

New Project (6)