Applying a jsonPath selector

Selectors are components that apply selection criteria to an inbound message and display the result in an out slot. The JsonPath component allows data to be interactively located and extracted from JSON structures using a special notation to represent the payload structure.
Prerequisites: You have a schema generating an output that can be filtered.
The following task shows how to use a JsonPath component for data selection.

Perform the following steps:
  1. Open the jsonToolkit palette, expand Inbound > Selectors and drag a JsonPath selector to a Wire Sheet and then open the selector’s property sheet view.
  2. Configure the path property using the syntax $.data.values.[0], as shown below, and save your changes.
    Image
    The result of the configuration displays in the Out property.

    For example, this path selects the first item in a values array (1): $.data.values.[0]. This is the schema payload:

    { 
      "messageType" : "line", 
      "data" : [
      { 
        "labels" : ["Sunday", "Monday"], 
        "values" : [ 1, 2 ] 
      } 
    }

    This example selects a single numeric value, however, there are other possibilities for selecting a subset of the incoming JSON:

    • $.data transfers the entire data object to the Out slot.
    • $.data.values selects the entire JSON array.

    Any expression containing a search with, for example, $..labels returns search results enclosed within an outer array.

These URLs to external web sites explain this powerful tool in detail.

  • https://goessner.net/articles/JsonPath/
  • http://jsonpath.com/
  • https://www.baeldung.com/guide-to-jayway-jsonpath