You can merge fields to create a list of values from the arrays in the record. Let’s say you have a record with an array of item names and a record with an array of prices, but you want to get a better summary of each item name and its price. You can use JSON to combine both data sets.
Individual object to single record transformation
In the example below, you’ve taken the individual itemsNames[*] and prices[*] fields and merged them under one item[*] object with the item[*].name and item[*].price as a list of values.
Input:
{ "itemsNames":[ "item1", "item2", "item3" ], "prices":[ 10, 20, 30 ] }
Rules:
Source data (input) | Transformed data (output) |
---|---|
itemsNames [*] | item[*].name |
prices[*] | item[*].prices |
Output:
{ "item": [ { "name": "item1", "prices": 10 }, { "name": "item2", "prices": 20 }, { "name": "item3", "prices": 30 } ] }
Multiple objects to single record transformation
You can transform multiple objects into a single record by repeating the parent object automatically. In the previous example, you took the individual itemsNames[*] and prices[*] fields and merged them under one item[*] object with the item[*].name and item[*].price as a list of values.
To transform each list of values into an individual object, you simply need to repeat the parent object. In this case, you’re repeating the item[*] object, each name and each price as a list of values to create one record.
Input:
{ "id": 100, "item": [ { "name": "Item1", "price": 10 }, { "name": "Item2", "price": 20 }, { "name": "Item3", "price": 30 } ] }
Rules:
Source data (input) | Transformed data (output) |
---|---|
id | *.id |
item[*].name | *.name |
item[*].price | *.prices |
Output:
[ { "name": "Item1", "price": 10, "id": 100 }, { "name": "Item2", "price": 20, "id": 100 }, { "name": "Item3", "price": 30, "id": 100 } ]
Comments
Please sign in to leave a comment.