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

  • @acesario , you can also just add [0] after @viktor_n’s expression.

    $Records.map(record => record.Award.map((x, index) => record.Award.slice(0, index + 1).filter(y => y == x).length))[0]
    

    And if you really need the “0” you can try and add .map(val => "0" + val)

    So full expression is: $Records.map(record => record.Award.map((x, index) => record.Award.slice(0, index + 1).filter(y => y == x).length).map(val => "0" + val))[0]

4 Replies

    • Thanks for the Solution. The Solution is almost what i need except the "Transaction_id should be displayed at the header level only. “The tenders” child array also displays the “TRANSACTION_ID” attribute which i don’t want to display at the tenders level.

      I tried removing by having empty expression variable for “transactiod_id” in the “Remove groupBy tenders” Snap but didn’t work. It would be really helpful if this is sorted.

      Thanks

  • receipt_no,item_id,quantity,item_total,item_gross,item_tax are item attributes grouped for each transaction_id.

    media_id,media_no,media_value are tenders attributes grouped for each transaction_id