Split cdt

I have this below cdt

{{id:1, name:"abc"},{id:2,name:"abc;pqr"}}

I need to transform this cdt into this:

{{id:1, name:"abc"},{id:2,name:"abc"},{id:2,name:"pqr"}}

Any code snippet for this?

  Discussion posts and replies are publicly visible

Parents
  • You'll need to split the second string on the semicolon - I assume that the semicolon is always used to separate the items? Then, you will need to create a couple of loops to loop through the items and create your new array. Lastly, I used a!flatten() to make it a single list instead of a list of lists. See a sample here:

    a!localVariables(
      local!array: {{id:1, name:"abc"},{id:2,name:"abc;pqr"}},
      a!flatten(
        a!forEach(
          items: local!array,
          expression: a!localVariables(
            local!id: fv!item.id,
            a!forEach(
              items: split(fv!item.name, ";"),
              expression: {
                id: local!id,
                name: fv!item
              }
            )
          )
        )
      )
    )

Reply
  • You'll need to split the second string on the semicolon - I assume that the semicolon is always used to separate the items? Then, you will need to create a couple of loops to loop through the items and create your new array. Lastly, I used a!flatten() to make it a single list instead of a list of lists. See a sample here:

    a!localVariables(
      local!array: {{id:1, name:"abc"},{id:2,name:"abc;pqr"}},
      a!flatten(
        a!forEach(
          items: local!array,
          expression: a!localVariables(
            local!id: fv!item.id,
            a!forEach(
              items: split(fv!item.name, ";"),
              expression: {
                id: local!id,
                name: fv!item
              }
            )
          )
        )
      )
    )

Children