Data Filtering & Querying

Slumber supports querying data structures to transform or reduce response data.

There are two main use cases for querying:

  • In chained template values, to extract data
    • Provided via chain's selector argument
  • In the TUI response body browser, to limit the response data shown

Regardless of data format, querying is done via JSONPath. For non-JSON formats, the data will be converted to JSON, queried, and converted back. This keeps querying simple and uniform across data types.

Querying Chained Values

Here's some examples of using queries to extract data from a chained value. Let's say you have two chained value sources. The first is a JSON file, called creds.json. It has the following contents:

{ "user": "fishman", "pw": "hunter2" }

We'll use these credentials to log in and get an API token, so the second data source is the login response, which looks like so:

{ "token": "abcdef123" }
    source: !file
      path: ./creds.json
    selector: $.user
    source: !file
      path: ./creds.json
    selector: $.pw
    source: !request
      recipe: login
    selector: $.token

# Use YAML anchors for de-duplication
base: &base
    Accept: application/json
    Content-Type: application/json

  login: !request
    <<: *base
    method: POST
    url: ""
    body: |
        "username": "{{chains.username}}",
        "password": "{{chains.password}}"

  get_user: !request
    <<: *base
    method: GET
    url: ""
      auth: "{{chains.auth_token}}"

While this example simple extracts inner fields, JSONPath can be used for much more powerful transformations. See the JSONPath docs or this JSONPath editor for more examples.

Querying Response in TUI

You can visually query a response body using the filter box at the bottom. Here is a full response, with no query applied:

Unfiltered response

And here it is with the query $.data applied:

Filtered response