0
votes

I'm facing issue to apply logic to remove one key from the array. Below i have added my payload that i am getting after processing now from here i want to remove the object key. How to remove the contact key dynamically?

 [{
    "TB1": [{
            "object": "TB1",
            "Name": 200
        },
        {
            "object": "TB1",
            "Name": 220
        }
    ]
  },
  {
    "TB2": [{
        "object": "TB2",
        "Field1": 100
    }]
  },
  {
    "TB3": [{
        "object": "TB3",
        "Field2": 1300
    }]
  }]

expected:

 [{
    "TB1": [{
            "Name": 200
        },
        {
            "Name": 220
        }
    ]
},
{
    "TB2": [{
        "Field1": 100
    }]
},
{
    "TB3": [{
        "Field2": 1300
    }]
}]
1

1 Answers

2
votes
output application/json
fun removeObject (obj) = (
    (obj - "object")
)
---
payload map (o) -> {
    (o mapObject (v,k) -> {
        (k): (v match {
            case a is Object -> removeObject(a)
            case a is Array -> a map (removeObject($))
            else -> v
        })
    })
}