Skip to main content
Skip table of contents

Filters

Filters can drill down into the data returned by the external data source or select a slice of data from it. To accomplish this task the JSONPath Syntax is used.

Filters are performed in sequence. This means the order of how the filters are created matters. Mostly drill down operations come before the filter operations.

In the following we will use a data source with this Json result to demonstrate an example:

CODE
{
  "userlist": [
    {
      "id": 1,
      "name": "Mario Speedwagon",
      "username": "mario"
    },
    {
      "id": 2,
      "name": "Anna Sthesia",
      "username": "anna"
    }
  ]
}

To perform a drill down into the data we create a filter with the following configuration

CODE
FilterPath: $.userlist[*]
Ignore on fail: false
Result is list: true

The FilterPath drills down into the data a returns the complete list of users. We also define that the result of this operation is a list and not a single value. After this operation the data looks like this:

CODE
[{
    "id": 1,
    "name": "Mario Speedwagon",
    "username": "mario"
},
{
    "id": 2,
    "name": "Anna Sthesia",
    "username": "anna"
}]

To demonstrate a filter using a variable see the following configuration

CODE
FilterPath: $[?(@.id=='{$.id}')]
Ignore on fail: true
Result is list: true

Because the drill down happened before this filter we don't need to select userlist again. The part
?(@.id=='{$.idVar}') uses the variable $.idVar which is surrounded by curly brackets. When the viewer enters 2 into the presented textfield the expression {$.idVar} would compile into 2. The complete result would be ?(@.id=='2') which means that we only select items from the list having the value 2 as id.

The ignore on fail is set to true this time meaning that we don't fail the rendering if the expression doesn't return a result. This is important for filters that could be empty and don't have a default value especially.

Filter syntax examples

  • $.userList[?(@.username=='mario')]

  • $.userList[?(@.id=={$.idVar})]

  • $.userList[?(@.name=='{$.nameVar}')]

Regex examples

  • $.userList[?(@.name=~/(mario)/g)] all users that contain mario in name

  • $.userList[?(@.name=~/(mario|anna)/g)] all users that contain mario or anna in name

  • $.userList[?(@.name=~/({$.searchVar})/g)]

  • $.userList[?(@.name=~/^((?!mario).)*$/g)] all users that do not contain mario in name

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.