cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Merging two arrays

manohar
Contributor

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"
      }

    ]
  }
]
1 ACCEPTED SOLUTION

j_angelevski
Contributor III

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
image
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
image
After this use Mapper with the following expression
image
You get the same result.

View solution in original post

6 REPLIES 6

manohar
Contributor

Thanks @j.angelevski. wondering can I add that to Concat mapper itself? I used your concat.

image

image1186ร—75 6.49 KB

j_angelevski
Contributor III

@manohar , this only works with jsonPath($, โ€œโ€), if you want to use it directly to an array the you need to use the built-in array function .sort(). @bojanvelevski already gave you a solution for that: Sort internal array - #2 by bojanvelevski