How to query array of objects

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:
I need to construct a query using XPath to find objects that have a member array with specific key:value.

Details (like screenshots):

I have a REST service that returns the following data:

{
    "content": [
        {
            "domain": "one",
            "tags": [
                {
                    "key": "foo",
                    "value": "bar"
                },
                {
                    "key": "baz",
                    "value": "blah"
                }
            ]
        },
        {
            "domain": "two",
            "tags": [
                {
                    "key": "foo",
                    "value": "bar"
                }
            ]
        },
        {
            "domain": "three",
            "tags": [
                {
                    "key": "baz",
                    "value": "blah"
                }
            ]
        }
    ],
    "totalElements": 3,
    "numberOfElements": 3
}

I can successfully query by “domain” with:

https://{{myServer}}/path/to/service?$filter=domain eq 'one'

What I want to do is query for all of the objects where key = foo and value = bar.

How I found the problem:
Still working on it.

I’ve already tried:

https://{{myServer}}/path/to/service?$filter=tags[foo] eq 'bar'

https://{{myServer}}/path/to/service?$filter=tags['foo'] eq 'bar'

https://{{myServer}}/path/to/service?$filter=tags.[foo] eq 'bar'

https://{{myServer}}/path/to/service?$filter=tags.key[foo] eq 'bar'

@aenagy Welcome to the community :partying_face:

You can try


https://{{myServer}}/path/to/service?$filter=tags[0].key eq 'foo'

Since you are trying to access the array inside in.

This tool will help to locate the elements.

Let me know if this works :slightly_smiling_face:

1 Like