This example take json file from source folder, split it based on json array’s elements to multiple payload, renamed then saved to multiple files in target folder. See below gif animation:
Input file:
Orders.txt
{
"Orders": [{
"OrderID": 2501,
"Customer": "Alex",
"Country": "USA",
"Items": [{
"ProductID": "P05",
"UnitPrice": 50,
"Quantity": 1,
"Variants": [{
"Color": "Blue",
"Quantity": 1
}
]
}
]
}, {
"OrderID": 2502,
"Customer": "Bob",
"Country": "UK",
"Items": [{
"ProductID": "P05",
"UnitPrice": 50,
"Quantity": 5,
"Variants": [{
"Color": "Blue",
"Quantity": 2
}, {
"Color": "Red",
"Quantity": 3
}
]
}, {
"ProductID": "P06",
"UnitPrice": 80,
"Quantity": 1,
"Variants": [{
"Color": "Yellow",
"Quantity": 1
}
]
}
]
}, {
"OrderID": 2503,
"Customer": "Peter",
"Country": "UK",
"Items": [{
"ProductID": "P07",
"UnitPrice": 120,
"Quantity": 10,
"Variants": [{
"Color": "Green",
"Quantity": 4
},{
"Color": "Yellow",
"Quantity": 6
}
]
}
]
}
]
}
Output file: 2501.txt
{
"OrderID": 2501,
"Customer": "Alex",
"Country": "USA",
"Items": [
{
"ProductID": "P05",
"UnitPrice": 50,
"Quantity": 1,
"Variants": [
{
"Color": "Blue",
"Quantity": 1
}
]
}
]
}
Output file: 2502.txt
{
"OrderID": 2502,
"Customer": "Bob",
"Country": "UK",
"Items": [
{
"ProductID": "P05",
"UnitPrice": 50,
"Quantity": 5,
"Variants": [
{
"Color": "Blue",
"Quantity": 2
},
{
"Color": "Red",
"Quantity": 3
}
]
},
{
"ProductID": "P06",
"UnitPrice": 80,
"Quantity": 1,
"Variants": [
{
"Color": "Yellow",
"Quantity": 1
}
]
}
]
}
Output file: 2503.txt
{
"OrderID": 2503,
"Customer": "Peter",
"Country": "UK",
"Items": [
{
"ProductID": "P07",
"UnitPrice": 120,
"Quantity": 10,
"Variants": [
{
"Color": "Green",
"Quantity": 4
},
{
"Color": "Yellow",
"Quantity": 6
}
]
}
]
}
The flow:
At “On New or Updated File” step, set read from Source folder, and post processing move to Archive folder.
The MIME Type set to ‘application/json’
At “For Each” step, Set to split by payload.Orders.
At “File Write” step, set write to Target folder, and set the output txt file name as payload.OrderID value.
🙂
Split Single File to Multiple File using For Each