Skip to content

Conditional removal of array entries #1277

Description

@suyashrails

I have a json like this

{
    "status": "ACTIVE",
    "users": [{
        "id": "1",
        "name": "Aaron",
        "accounts": [{
            "id": 11,
            "value": "account_11"
        }, {
            "id": "12",
            "value": "account_12"
        }]
    }, {
        "id": "2",
        "name": "Rodney",
        "accounts": [{
            "id": 22,
            "value": "account_22"
        }]
    }, {
        "id": "3",
        "name": "Clayton",
        "accounts": [{
            "id": 33,
            "value": "account_33"
        }]
    }]
}

I want to keep the users array empty when status is "PENDING", "INACTIVE" or "BLOCKED" but not of any other value of status.

e.g.

  1. for above json no change
  2. for following json
{
    "status": "BLOCKED",
    "users": [{
        "id": "1",
        "name": "Aaron",
        "accounts": [{
            "id": 11,
            "value": "account_11"
        }, {
            "id": "12",
            "value": "account_12"
        }]
    }, {
        "id": "2",
        "name": "Rodney",
        "accounts": [{
            "id": 22,
            "value": "account_22"
        }]
    }, {
        "id": "3",
        "name": "Clayton",
        "accounts": [{
            "id": 33,
            "value": "account_33"
        }]
    }]
}

it should result in

{
    "status": "BLOCKED",
    "users": []
}

How can this be done with Jolt specs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions