cancel
Showing results for 
Search instead for 
Did you mean: 

Combine multiple arrays

manohar
Contributor

hi there,

I have following json

[
  {
    "docname": [
      "Coupa_Supplier_SB_Tax_Cert_PO_4501923290",
      "Coupa_Supplier_SB_Tax_Cert_PO_450192323"
    ],
    "id": 16758,
    "docext": [
      "pdf",
      "pdf"
    ],
    "IDOC": {
      "@BEGIN": "1",
      "EDI_DC40": {
        "@SEGMENT": "1"
      }
    },
    "docid": [
      "FOL18          4 EXT48000000000776",
      "FOL18          4 EXT480000000007236"
    ]
  }
]

that i need to convert to

[
  {
  "attachments": [
  	{
  		"docname": "Coupa_Supplier_SB_Tax_Cert_PO_4501923290",
  		"id": 16758,
  		"docext": "pdf",
  		"docid": "FOL18          4 EXT48000000000776"
  	},
  	{
  		"docname": "Coupa_Supplier_SB_Tax_Cert_PO_450192323",
  		"id": 16758,
  		"docext": "pdf",
  		"docid": "FOL18          4 EXT480000000007236"
  	}
  ],
  "IDOC": {
      "@BEGIN": "1",
      "EDI_DC40": {
        "@SEGMENT": "1"
      }
    }
  }
]

any help is greatly appreciated.

thanks
Manohar

1 ACCEPTED SOLUTION

Aleksandar_A
Contributor III

Hi @manohar,

You can try by using Mapper Snap with the following expression for the attachments:

sl.range(0,$docname.length).map((x,ind) => {"docname":$docname[ind],"id":$id,"docext":$docext[ind],"docid":$docid[ind]})

Try with this, and let me know if this helps you.

BR,
Aleksandar.

View solution in original post

2 REPLIES 2

Aleksandar_A
Contributor III

Hi @manohar,

You can try by using Mapper Snap with the following expression for the attachments:

sl.range(0,$docname.length).map((x,ind) => {"docname":$docname[ind],"id":$id,"docext":$docext[ind],"docid":$docid[ind]})

Try with this, and let me know if this helps you.

BR,
Aleksandar.

hi @AleksandarAngelevski

wow!! you make it look so simple. thank you very much for your help.

Manohar