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

To fix the pipeline to convert to array

manohar
Contributor

Hi there,
I have the following JSON

[
  {
    "POSEX":"00010",
    "E1EDPT1": [
      {
        "E1EDPT2": [
          {
            "@SEGMENT": "1",
            "TDLINE": "KIT,HIGH SPEED PINION (HSP),",
            "TDFORMAT": "*"
          },
          {
            "@SEGMENT": "1",
            "TDLINE": "<br/>",
            "TDFORMAT": "/"
          }
        ]
      },
      {
        "E1EDPT2": [
          {
            "@SEGMENT": "1",
            "TDLINE": "*NSK bearings ",
            "TDFORMAT": "*"
          },
          {
            "@SEGMENT": "1",
            "TDLINE": "STF*"
          }
        ]
      }
    ]
  },
  {
    "POSEX":"00020",
    "E1EDPT1": {
      "@SEGMENT": "1",
      "E1EDPT2": [
        {
          "@SEGMENT": "1",
          "TDFORMAT": "*"
        },
        {
          "@SEGMENT": "1",
          "TDLINE": "<br/>",
          "TDFORMAT": "/"
        },
        {
          "@SEGMENT": "1",
          "TDLINE": "MATERIAL DESCRIPTION :REVERSING",
          "TDFORMAT": "/"
        }
      ]
    }
  }
]

And expecting following

[
  {
    "order-lines": [
      {
        "line-num": "00010",
        "attachments": [
          {
            "text": "KIT,HIGH SPEED PINION (HSP),<br/>"
          },
          {
            "text": "*NSK bearings STF*"
          }
        ]
      },
      {
        "line-num": "00020",
        "attachments": [
          {
            "text": ",<br/>,MATERIAL DESCRIPTION :REVERSING "
          }
        ]
      }
    ]
  }
]

I tried to build following pipeline and is not working

toArray_2023_05_29.slp (13.4 KB)

it works fine for following

[
  {
    "POSEX":"00010",
    "E1EDPT1": {
      "@SEGMENT": "1",
      "E1EDPT2": [
        {
          "@SEGMENT": "1",
          "TDFORMAT": "*"
        },
        {
          "@SEGMENT": "1",
          "TDLINE": "<br/>",
          "TDFORMAT": "/"
        },
        {
          "@SEGMENT": "1",
          "TDLINE": "MATERIAL DESCRIPTION :REVERSING CONTACTOR, SOLID STATE",
          "TDFORMAT": "/"
        }
      ]
    }
  },
  {
    "POSEX":"00020",
    "E1EDPT1": {
      "@SEGMENT": "1",
      "E1EDPT2": [
        {
          "@SEGMENT": "1",
          "TDFORMAT": "*"
        },
        {
          "@SEGMENT": "1",
          "TDLINE": "<br/>",
          "TDFORMAT": "/"
        },
        {
          "@SEGMENT": "1",
          "TDLINE": "MATERIAL DESCRIPTION :REVERSING ",
          "TDFORMAT": "/"
        }
      ]
    }
  }
]

and gets what expected

[
  {
    "order-lines": [
      {
        "line-num": "00010",
        "attachments": [
          {
            "text": ",<br/>,MATERIAL DESCRIPTION :REVERSING CONTACTOR, SOLID STATE"
          }
        ]
      },
      {
        "line-num": "00020",
        "attachments": [
          {
            "text": ",<br/>,MATERIAL DESCRIPTION :REVERSING "
          }
        ]
      }
    ]
  }
]

Any help in fixing the pipeline

1 ACCEPTED SOLUTION

Abhishek_Soni37
Contributor

I created this expression that supports both object and array if thatโ€™s how the external system is sending data to Snaplogic. This will work, give it a try. You can do a little fine-tuning to this.

Let me know if this works.
toArray_2023_05_29 (1).slp (7.4 KB)
image

Cheers,

View solution in original post

4 REPLIES 4

Abhishek_Soni37
Contributor

Hey Manohar,

I noticed that in the first payload, there is an issue with the format, itโ€™s inconsistent. The second payload is consistent and hence itโ€™s working fine.

Can you confirm, if the first payload is not a typo? Let me know
image

Abhishek_Soni37
Contributor

I created this expression that supports both object and array if thatโ€™s how the external system is sending data to Snaplogic. This will work, give it a try. You can do a little fine-tuning to this.

Let me know if this works.
toArray_2023_05_29 (1).slp (7.4 KB)
image

Cheers,

hi thanks @Soni37,

Works like perfectly except for one thing, I need to add 2 static elements along with the text, I tried a few ways but was not able to add to it. can you point out on how to add that?

โ€œtypeโ€:โ€œAttachmentTextโ€,
โ€œintentโ€:โ€œSupplierโ€,

[
  {
    "LINES": [
      {
        "POSEX": "00010",
        "attachments": [
          {
          	"type":"AttachmentText",
          	"intent":"Supplier",
            "text": "KIT,HIGH SPEED PINION (HSP),,<br/>"
          },
          {
            "type":"AttachmentText",
          	"intent":"Supplier",
            "text": "*NSK bearings ,STF*"
          }
        ]
      },
      {
        "POSEX": "00020",
        "attachments": [
          {
            "type":"AttachmentText",
          	"intent":"Supplier",
            "text": ",<br/>,MATERIAL DESCRIPTION :REVERSING"
          }
        ]
      }
    ]
  }
]

Thank you again for your help.

Hi @Soni37, please ignore it. I got it. Thank you again.