cancel
Showing results for 
Search instead for 
Did you mean: 

Route based on grand child value

manohar
Contributor

Hi there, I have this structure json. I need to route the json based on attachment in below json, if exist or not

input json

[
  {
    "data": {
      "po-number": "4501918519_2",
      "order-lines": [
        {
          "id": {
            "@type": "integer",
            "$": "40950"
          },
          "attachments": {
            "@type": "array"
          }
        },
        {
          "id": {
            "@type": "integer",
            "$": "40951"
          },
          "attachments": {
            "@type": "array",
            "***attachment**":* {
              "id": {
                "@type": "integer",
                "$": "1884472"
              },
              "type": "AttachmentText",
              "intent": "Supplier",
              "text": "SURGE TRAP 600V"
            }
          }
        }
      ]
    },
    "headerid": "16825",
    "IDOC": {
      "@BEGIN": "1",
      "EDI_DC40": {
        "DOCNUM": "0000000046984396"
      }
    },
    "Origattachments": [
      {
        "type": "AttachmentText",
        "intent": "Supplier",
        "text": "test"
      }
    ]
  }
]

my needed outputs
output 1 -

[
  {
    "data": {
      "po-number": "4501918519_2",
      "order-lines": [
        {
          "id": {
            "@type": "integer",
            "$": "40950"
          },
          "attachments": {
            "@type": "array"
          }
        }
      ]
    },
    "headerid": "16825",
    "IDOC": {
      "@BEGIN": "1",
      "EDI_DC40": {
        "DOCNUM": "0000000046984396"
      }
    },
    "Origattachments": [
      {
        "type": "AttachmentText",
        "intent": "Supplier",
        "text": "test"
      }
    ]
  }
]

output 2

[
  {
    "data": {
      "po-number": "4501918519_2",
      "order-lines": [
        {
          "id": {
            "@type": "integer",
            "$": "40951"
          },
          "attachments": {
            "@type": "array",
            "attachment": {
              "id": {
                "@type": "integer",
                "$": "1884472"
              },
              "type": "AttachmentText",
              "intent": "Supplier",
              "text": "SURGE TRAP 600VDC"
            }
          }
        }
      ]
    },
    "headerid": "16825",
    "IDOC": {
      "@BEGIN": "1",
      "EDI_DC40": {
        "DOCNUM": "0000000046984396"
      }
    },
    "Origattachments": [
      {
        "type": "AttachmentText",
        "intent": "Supplier",
        "text": "test"
      }
    ]
  }
]

input json structure pic
image

any guidance on how I can achieve it?

Thanks
Manohar

1 ACCEPTED SOLUTION

So you want every order line to be as a separate object, or you want two objects:

  • Object A: with order lines that contain ***attachment***

  • Object B: with order lines that doesn’t

SL-comm-route-based-on-grand-child_2023_03_02.slp (7.6 KB)
This pipeline creates as many objects, as there are in the order-lines array under data.

View solution in original post

5 REPLIES 5

Thanks again, @AleksandarAngelevski you make it look so easy.