08-25-2021 07:09 AM
Hi there,
I have 2 arrays that I need to merge; I have used Merge in Join Snap but they are not coming in as Output below. seems simple but missing something.
Any guidance?
Thanks
Manohar
INPUT
**Array 1**
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 31103"
}
]
}
]
**Array 2**
[
{
"order-lines": [
{
"line-num": "00020",
"description": "Test 31104"
},
{
"line-num": "00030",
"description": "Test 10220"
}
]
}
]
OUTPUT
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 31103"
},
{
"line-num": "00020",
"description": "Test 31104"
},
{
"line-num": "00030",
"description": "Test 10220"
}
]
}
]
Solved! Go to Solution.
08-25-2021 07:57 AM
Hi @manohar ,
After the input data you can use JSON Splitter to split the input data on $order-lines, then simply use Group by N with the following
Result:
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 31103"
},
{
"line-num": "00020",
"description": "Test 31104"
},
{
"line-num": "00030",
"description": "Test 10220"
}
]
}
]
This is assuming you have only one data source, if you have two then use Join with following setting
After this use Mapper with the following expression
You get the same result.
08-25-2021 07:57 AM
Hi @manohar ,
After the input data you can use JSON Splitter to split the input data on $order-lines, then simply use Group by N with the following
Result:
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 31103"
},
{
"line-num": "00020",
"description": "Test 31104"
},
{
"line-num": "00030",
"description": "Test 10220"
}
]
}
]
This is assuming you have only one data source, if you have two then use Join with following setting
After this use Mapper with the following expression
You get the same result.
08-25-2021 08:43 AM
that did the trick. thanks @j.angelevski
09-02-2021 08:37 PM
@j.angelevski , I have one problem here…
when concatenating, its concatenating Array1 followed by Array2, which is good. but however I need that to be ordered by line-num value. as not always its will be that order.
**Array 1**
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 31103"
},
{
"line-num": "00030",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 1313"
}
]
}
]
**Array 2**
[
{
"order-lines": [
{
"line-num": "00020",
"description": "Test 31104"
}
]
}
]
Output should be
[
{
"order-lines": [
{
"line-num": "00010",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 31103"
},
{
"line-num": "00020",
"description": "Test 31104"
},
{
"line-num": "00030",
"attachments": {
"type": "AttachmentText",
"intent": "Supplier",
"text": "2021-08-25 09:57 :- Test"
},
"description": "Test 1313"
}
]
}
]
May I know how I can achieve that?
Thanks
Manohar
09-03-2021 12:33 AM
@manohar ,
You can use jsonPath($, "order-lines.sort_asc(value['line-num'])")
, this will sort the $order-lines
array.