Forum Discussion

manohar's avatar
manohar
Contributor
3 years ago
Solved

To fix the pipeline to convert to array

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

  • 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)

    Cheers,

4 Replies

  • akidave's avatar
    akidave
    Employee

    The preview shows the since multiple documents can be streamed, each document being streamed is a map. The REST POST snap will take each document and write it out to the endpoint, as a map. You can change the POST endpoint to a test endpoint created in a service like https://requestb.in/, to verify whether the right data is being posted.

    The Zendesk API error response would have more details. It is possible the right content type was not set, add a HTTP Header in the POST snap, with key “Content-Type” and value “application/json”