Skip to main content

jsonPathSearch

A Workflow Engine function that performs a JSONPath search against JSON data in the supplied field and returns the results.

This function uses the JMESPath variant of JSONPath to allow filtered extraction of data from JSON held in a source field or workflowContext key.

Detailed examples of the JMESPath syntax are available here, where it’s also possible to test queries against sample data.

This function is available as a feature of the Add-ons v2.4 download and later.

This function is available for event, alert, and Situation workflows.

Back to Workflow Engine Functions Reference.

Arguments

Workflow Engine function jsonPathSearch takes the following arguments:

Name

Required

Type

Description

source

yes

string

The JSON data to be searched.

search

yes

string

The search expression. This uses the JMESPath syntax.

destination

no

string

The destination field to store the search results. If not supplied, the results with be written to workflowContext.searchResults.

Example

The following example demonstrates typical use of Workflow Engine function jsonPathSearch.

Given the following data help in custom_info.eventDetails:

{
  "list": [
      {
        "name": "SupportGroup",
        "value": "Support Group 1",
        "owner": "fred@bedrock.com",
        "id": 1234
      },
      {
        "name": "SupportGroup",
        "value": "Support Group 2",
        "owner": "wilma@bedrock.com",
        "id": 1235
      },
      {
        "name": "ServiceName",
        "value": "Service 1",
        "location": "London"
      },
      {
        "name": "ServiceName",
        "value": "Service 2",
        "location": "Paris"
      }
  ],
  "object": {
    "Service 1": {
        "Service Classification": "Technical Service",
                "Type": "Depends on::Used by",
                "SupportGroup": "Support Group 1",
                "Class": "Application Service",
                "ImpactedService": "Service 1"
    },
    "Service 2": {
        "Service Classification": "Business Service",
                "Type": "Runs on::Runs",
                "SupportGroup": "Support Group 2",
                "Class": "Application Service",
                "ImpactedService": "Service 2"
    }
  }
}

To extract the SupportGroup with "id" : 1234 from the list and write the result to the default workflowContext.searchResults location, we would supply the following arguments:

Argument Name

Value

source

custom_info.eventDetails

search

list[?id > '1234']

destination

Which the UI translates to:

{"source":"custom_info.eventDetails","search":"list[?id > `1234`]"}

For the example input, this would return the following into the workflowContext:

{
    "searchResults": [
        {
            "owner": "fred@example.com",
            "name": "SupportGroup",
            "id": 1235,
            "value": "Support Group 2"
        }
    ]
}

Other example queries:

  • Extract the owners of the listed SupportGroups: list[?name == 'SupportGroup'].{"owner": owner} which would produce:

    {
        "searchResults": [
            {
                "owner": "fred@example.com"
            },
            {
                "owner": "fred@example.com"
            }
        ]
    }
  • Extract the details for Business Services: object.* | [?"Service Classification" == 'Business Service'] which would produce:

    {
        "searchResults": [
            {
                "Service Classification": "Business Service",
                "SupportGroup": "Support Group 2",
                "Type": "Runs on::Runs",
                "Class": "Application Service",
                "ImpactedService": "Service 2"
            }
        ]
    }

This example features the use of a piped query and accessing keys with spaces. The first part of the query object.* produces a list of the values under object , and the second part of the query [?"Service Classification" == 'Business Service'] filters this list.