Filter Object Array

Provides the ability to filter an array of multi-level/complex objects by the definition provided.

Version 1

HTTP Request
POST /ado/v1/FilterObjectArray

Header

ParameterDescription
Ocp-Apim-Subscription-KeyThe subscription key you received when you purchased a plan.

Request Body

Mandatory

ParameterTypeDescription
dataobject[]Array of complex, multi-level objects.
filterstringA C# style string that performs the filter. Please see more information below on how this string should be constructed.

Property Conversion

This operation works in a dynamic way, therefore, each property of the JSON payload that is being filtered on will need to be statically/strongly typed within the filter statement.

This is achieved via the use of the Convert class in C#.

https://learn.microsoft.com/en-us/dotnet/api/system.convert

There are numerous methods available when it comes to converting from one value type to another but it is likely that only the core set will need to be utilised at any given time.

The core set of methods are listed below.

Convert.ToBoolean()
Convert.ToDateTime()
Convert.ToDecimal()
Convert.ToDouble()
Convert.ToInt32()
Convert.ToInt64()
Convert.ToString()

For more information on built in data types within C#, please refer to this link … https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/built-in-types

You’re more than welcome to experiment and use the methods other than those listed above.

Please refer to the examples provided for more information on how to apply the conversion.

Comparison Operators

Comparison operators used in the filter process need to follow the C# syntax.

OperatorExplanation
==Equals
>Greater Than
<Less Than
!=Not Equals
>=Greater Than or Equal
<=Less Than or Equal
&&And
||Or

Examples

Example 1
Example 2
Example 3
Example 4

This example demonstrates a complex array of multi-level objects filtered by property numericField3 where the value is greater than or equal to 200.

Request

{
    "filter": "Convert.ToInt32(numericField3) >= 200",
    "data": [
        {
            "textField1": "Value 1.1",
            "textField2": "Value 1.2",
            "textField3": "Value 1.3",
            "numericField1": 744,
            "numericField2": {
                "numericField2_1": 123.456,
                "numericField2_2": 429
            },
            "numericField3": 114
        },
        {
            "textField1": "Value 2.1",
            "textField2": "Value 2.2",
            "textField3": "Value 2.3",
            "numericField1": 987,
            "numericField2": {
                "numericField2_1": 456.789,
                "numericField2_2": 562
            },
            "numericField3": 265
        },
        {
            "textField1": "Value 3.1",
            "textField2": "Value 3.2",
            "textField3": "Value 3.3",
            "numericField1": 235,
            "numericField2": {
                "numericField2_1": 424.231,
                "numericField2_2": 246
            },
            "numericField3": 946
        }
    ]
}
Code language: JSON / JSON with Comments (json)

Request

[
    {
        "textField1": "Value 1.1",
        "textField2": "Value 1.2",
        "textField3": "Value 1.3",
        "numericField1": 744,
        "numericField2": {
            "numericField2_1": 123.456,
            "numericField2_2": 429
        },
        "numericField3": 114
    },
    {
        "textField1": "Value 2.1",
        "textField2": "Value 2.2",
        "textField3": "Value 2.3",
        "numericField1": 987,
        "numericField2": {
            "numericField2_1": 456.789,
            "numericField2_2": 562
        },
        "numericField3": 265
    }
]
Code language: JSON / JSON with Comments (json)

This example demonstrates a complex array of multi-level objects filtered by property numericField2.numericField2_2 where the value is greater than or equal to 400.

Unlike the firs example, this example drops down a level within the hierarchy of properties filtering on a lower level.

Request

{
    "filter": "Convert.ToInt32(numericField2.numericField2_2) >= 400",
    "data": [
        {
            "textField1": "Value 1.1",
            "textField2": "Value 1.2",
            "textField3": "Value 1.3",
            "numericField1": 744,
            "numericField2": {
                "numericField2_1": 123.456,
                "numericField2_2": 429
            },
            "numericField3": 114
        },
        {
            "textField1": "Value 2.1",
            "textField2": "Value 2.2",
            "textField3": "Value 2.3",
            "numericField1": 987,
            "numericField2": {
                "numericField2_1": 456.789,
                "numericField2_2": 562
            },
            "numericField3": 265
        },
        {
            "textField1": "Value 3.1",
            "textField2": "Value 3.2",
            "textField3": "Value 3.3",
            "numericField1": 235,
            "numericField2": {
                "numericField2_1": 424.231,
                "numericField2_2": 246
            },
            "numericField3": 946
        }
    ]
}
Code language: JSON / JSON with Comments (json)

Response

[
    {
        "textField1": "Value 1.1",
        "textField2": "Value 1.2",
        "textField3": "Value 1.3",
        "numericField1": 744,
        "numericField2": {
            "numericField2_1": 123.456,
            "numericField2_2": 429
        },
        "numericField3": 114
    },
    {
        "textField1": "Value 2.1",
        "textField2": "Value 2.2",
        "textField3": "Value 2.3",
        "numericField1": 987,
        "numericField2": {
            "numericField2_1": 456.789,
            "numericField2_2": 562
        },
        "numericField3": 265
    }
]
Code language: JSON / JSON with Comments (json)

This example demonstrates a complex array of multi-level objects filtered by property numericField2.numericField2_1 where the ceiling value is equal to 124.

A more complex filter has been applied that makes use of other C# classes during the filter operation. In this example, the number being filtered on is first converted to a double and then the ceiling (https://learn.microsoft.com/en-us/dotnet/api/system.math.ceiling) of the value is found which is then used in the filter comparison.

Request

{
    "filter": "Math.Ceiling(Convert.ToDouble(numericField2.numericField2_1)) == 124",
    "data": [
        {
            "textField1": "Value 1.1",
            "textField2": "Value 1.2",
            "textField3": "Value 1.3",
            "numericField1": 744,
            "numericField2": {
                "numericField2_1": 123.456,
                "numericField2_2": 429
            },
            "numericField3": 114
        },
        {
            "textField1": "Value 2.1",
            "textField2": "Value 2.2",
            "textField3": "Value 2.3",
            "numericField1": 987,
            "numericField2": {
                "numericField2_1": 456.789,
                "numericField2_2": 562
            },
            "numericField3": 265
        },
        {
            "textField1": "Value 3.1",
            "textField2": "Value 3.2",
            "textField3": "Value 3.3",
            "numericField1": 235,
            "numericField2": {
                "numericField2_1": 424.231,
                "numericField2_2": 246
            },
            "numericField3": 946
        }
    ]
}
Code language: JSON / JSON with Comments (json)

Response

[
    {
        "textField1": "Value 1.1",
        "textField2": "Value 1.2",
        "textField3": "Value 1.3",
        "numericField1": 744,
        "numericField2": {
            "numericField2_1": 123.456,
            "numericField2_2": 429
        },
        "numericField3": 114
    }
]
Code language: JSON / JSON with Comments (json)

This example demonstrates a complex array of multi-level objects filtered by property textField1 where the value of that field contains the text Value 2.

The conversion to the static types will also open up additional methods that are able to be made use of during the filtering process. String values specifically have a set of methods attached to them.

More information can be found via following this link … https://learn.microsoft.com/en-us/dotnet/api/system.string

It also shows the use of an OR statement within the filter expression.

Request

{
    "filter": "Convert.ToString(textField1).Contains(\"2.\") || Convert.ToString(textField1).Contains(\"3.\")",
    "data": [
        {
            "textField1": "Value 1.1",
            "textField2": "Value 1.2",
            "textField3": "Value 1.3",
            "numericField1": 744,
            "numericField2": {
                "numericField2_1": 123.456,
                "numericField2_2": 429
            },
            "numericField3": 114
        },
        {
            "textField1": "Value 2.1",
            "textField2": "Value 2.2",
            "textField3": "Value 2.3",
            "numericField1": 987,
            "numericField2": {
                "numericField2_1": 456.789,
                "numericField2_2": 562
            },
            "numericField3": 265
        },
        {
            "textField1": "Value 3.1",
            "textField2": "Value 3.2",
            "textField3": "Value 3.3",
            "numericField1": 235,
            "numericField2": {
                "numericField2_1": 424.231,
                "numericField2_2": 246
            },
            "numericField3": 946
        }
    ]
}
Code language: JSON / JSON with Comments (json)

Response

[
    {
        "textField1": "Value 2.1",
        "textField2": "Value 2.2",
        "textField3": "Value 2.3",
        "numericField1": 987,
        "numericField2": {
            "numericField2_1": 456.789,
            "numericField2_2": 562
        },
        "numericField3": 265
    },
    {
        "textField1": "Value 3.1",
        "textField2": "Value 3.2",
        "textField3": "Value 3.3",
        "numericField1": 235,
        "numericField2": {
            "numericField2_1": 424.231,
            "numericField2_2": 246
        },
        "numericField3": 946
    }
]
Code language: JSON / JSON with Comments (json)