hardcoder
hardcoder

Reputation: 184

Odata filter for JSON object inside another JSON object

I have a odata service which return a Json object like below and i want to filter data on country. Is it possible?

{
"Name": "Abc",
"Gender": "Male",
"Address": [
              {
                "Street": "Mystreet",
                "City": "Somecity",
                "Country": "Somecountry",
              }
           ]
}

I know we can filter it on gender using "service url ? $filter= Gender eq male" but how do i filter it on country?

Upvotes: 2

Views: 4439

Answers (1)

TomDoesCode
TomDoesCode

Reputation: 3681

Since this is an array, you can use the OData functions any and all. In your case, I would guess that you would want to use any (meaning, all people where they have any address with this country.

To achieve that with your url, it would be something like this:

People?$filter=Address/any(address: address/Country eq 'Somecountry')

Here is an example using the example TripPin services that is very similar: http://services.odata.org/V4/(S(gl4oqd3rz5uzuqjryt1be5mr))/TripPinServiceRW/People?$filter=AddressInfo/any(address: address/Address eq '187 Suffolk Ln.')

Upvotes: 1

Related Questions