由于您想要合并多个 xml(json) 文件的部分内容,并且您的示例很复杂,所以我简化了它们。
您的要求相当于合并xml文件
<orderQuote>
<order_id>AZS000001</order_id>
<quote_id>345678</quote_id>
<rate_id>ABC001</rate_id>
</orderQuote>
and
<orderQuote>
<order_id>AZS000001</order_id>
<quote_id>8975545</quote_id>
<rate_id>ABC002</rate_id>
</orderQuote>
to
<orderQuote>
<order_id>AZS000001</order_id>
<quotationCollection>
<quotation>
<quote_id>8975545</quote_id>
<rate_id>ABC002</rate_id>
</quotation>
<quotation>
<quote_id>345678</quote_id>
<rate_id>ABC001</rate_id>
</quotation>
</quotationCollection>
</orderQuote>
For this requirement, I initialize four variables at first(the variable "isFirstTime" is used to judge if it is the first loop in for each).
![enter image description here](https://i.stack.imgur.com/2qFQw.png)
Then I connect to ftp and parse the xml file get from ftp to json format.
![enter image description here](https://i.stack.imgur.com/QpzXr.png)
Next, I set the variable value with "order_id"(in this step, you may need to set some other variables such as "username", "user_first_name".....)
![enter image description here](https://i.stack.imgur.com/s6o67.png)
Next step, I create a "if" condition to do different work.
![enter image description here](https://i.stack.imgur.com/ItlfM.png)
At bottom of the "For each" loop, we need to set the variable "isFirstTime" to false.
![enter image description here](https://i.stack.imgur.com/fnN0x.png)
After complete the "For each" loop, we have last two steps.
The expression of "fx concat(...)" is
concat(concat(concat(concat('{"orderQuote":{"order_id":"', variables('order_id')), '","quotationCollection":['), variables('jsonstring')), ']}}')
之后我们就可以得到json格式的结果文件。
{
"orderQuote": {
"order_id": "AZS000001",
"quotationCollection": [
{
"quotation": {
"quote_id": "345678",
"rate_id": "ABC001"
}
},
{
"quotation": {
"quote_id": "8975545",
"rate_id": "ABC002"
}
}
]
}
}
By the way, we'd better to do some settings before we use "For each" loop, click the "…" icon beside the "For each" action --> click "Settings" and then enable "Concurrency Control" and change the "Degree of Parallelism" to 1.
![enter image description here](https://i.stack.imgur.com/41wTY.png)