Search code examples
odata

Filter empty object in odata


There is an oData service i want to call. We have an model that has an field Parent. The service tells me that the parent is an object with an iv that is an string inside. So we get the following model from the oData service:

{
"total": 0,
"items": [
    {
    "id": "string",
    "data": {
        "Title": {
            "en": "string",
            "nl": "string"
        },
        "Parent": {
            "iv": [
                "string"
            ]
        },
    }
]
}

Now when we get data back it looks like this:

{
    "total": 2,
    "items": [
        {
            "id": "6204c07d-1aef-4bd2-9646-e3ca36c63784",
            "data": {
                "Title": {
                    "en": "Test 1",
                    "nl": "Test 1"
                },
                "Parent": {
                    "iv": []
                },
            },
        },
        {
            "id": "bfd1b084-4166-4fec-9032-08047c8313d2",
            "data": {
                "Title": {
                    "en": "Test 2",
                    "nl": "Test 2"
                },
                "Parent": {
                    "iv": [
                        "6204c07d-1aef-4bd2-9646-e3ca36c63784"
                    ]
                },
            },
        },
}

Now i want to filter on all the items where parent is [] (so no parent selected). I've tried the following filters but all without success

  • data/Parent/iv eq [] | Returns 0 results

  • data/Parent/iv eq null | Returns 0 results

  • data/Parent eq null | Returns 0 results

  • length(data/Parent/iv) eq 0 | OData operation is not supported

  • not data/Parent/any() | Any/All may only be used following a collection.

  • not data/Parent/any() | Any/All may only be used following a collection.

  • data/Parent/iv/$count eq 0 | Server error


Solution

  • Found that for this case the following works:

    • empty(data/Parent/iv)