Filtering Responses

Responses can be large, and most of the time you only care about a small part of them. Response Filters let you run a query against the current response body to pull out, transform, or reshape exactly the data you want — without leaving HTTPBot.

The Filter Response view with a jq query in the input bar and the filtered JSON result above it.The Filter Response view with a jq query in the input bar and the filtered JSON result above it.The Filter Response view with a jq query in the input bar and the filtered JSON result above it.

What filtering does

When you filter a response, HTTPBot runs your query against the body and shows the result in a read-only view above the query input. The original response is left untouched — filtering is non-destructive, so you can change the query as many times as you like and immediately see the new result. The result view updates as you type (after a brief pause).

The filtering feature works on text responses such as JSON, XML, and HTML.

Opening the filter view

From the response Body tab, tap the Filter Response button in the bottom toolbar. This opens the filtering view as a sheet.

The filter view borrows the same niceties as the response body: it's syntax-highlighted, and you can toggle Wrap Response from its menu.

See Viewing Responses for more on the response view.

Filter languages

HTTPBot supports three query languages. Pick the one that matches your response in the language selector at the right of the input bar. HTTPBot defaults to a sensible choice based on the response's content type (jq for JSON, XPath for XML/HTML), but you're free to switch.

Language Best for Powered by
jq JSON the SwiftJQ jq engine
JSONPath JSON built-in JSONPath evaluator
XPath XML / HTML built-in XPath 1.0 evaluator

A row of quick-insert buttons above the input bar inserts common symbols for the selected language (such as ., |, [, ] for jq, or /, @, = for XPath), so you can build queries faster on a touch keyboard.

jq (JSON)

jq is a powerful, expressive language for slicing and transforming JSON. For a response like the one below:

{
  "items": [
    { "id": 1, "name": "Widget" },
    { "id": 2, "name": "Gadget" }
  ]
}

A query of:

.items[].name

returns each item's name. jq can do far more than extraction — filtering with select(...), building new objects, mapping, and so on. The full jq manual is a tap away from the view's Help menu.

JSONPath (JSON)

JSONPath uses a path-like syntax rooted at $. The equivalent of the jq example above is:

$.items[*].name

JSONPath is a good choice if you're already familiar with it from other tools.

XPath (XML / HTML)

XPath queries XML and HTML documents. For this XML:

<catalog>
  <item><name>Widget</name></item>
  <item><name>Gadget</name></item>
</catalog>

A query of:

//item/name

selects every name element under an item. HTTPBot evaluates XPath 1.0, and automatically uses the right engine depending on whether the response is XML or HTML.

Response Filters (saved queries)

If you find yourself running the same query again and again, save it as a Response Filter so you can reuse it later.

From the filter view's menu:

The menu also lists your recent saved queries under a Queries section — tap one to apply it instantly. When you apply a saved filter that uses a different language than the one currently selected, HTTPBot switches the language for you automatically.

You can also manage your saved filters globally from Settings → Response Filters, where you can add, edit, and remove them outside of any particular response.

The Response Filters list in Settings with several saved queries.The Response Filters list in Settings with several saved queries.The Response Filters list in Settings with several saved queries.

Filtering with Shortcuts

The same filtering engine is available outside the app as a Shortcuts action called Query/Filter JSON, XML or HTML. Feed it some text and a query, and it returns the filtered result — handy for chaining HTTPBot into larger automations that don't involve sending a request at all.

See Shortcuts for details.

Tips

Related pages