How to filter a JSON response with jq in API Spector

Roy de Kleijn Roy de Kleijn · · 2 min read
How to filter a JSON response with jq in API Spector

A JSON response can be large, and often you only want one field, a mapped list, or the items that match a condition. API Spector lets you filter the response with jq, the standard command-line JSON processor, without leaving the response view.

Where to type it

Send a request and open the response Body view. When the body is JSON, a jq filter box appears in the view bar. Type an expression and the view shows the filtered result in place of the full body, formatted and syntax-highlighted. Clear the box to get the whole body back.

Examples

  • .data returns just the data field.
  • .users | map(.name) returns the list of names.
  • [.items[] | select(.price > 100)] keeps only the items over 100.
  • .results | length returns the count.
  • keys lists the top-level keys.

It is the real jq

The filter runs the actual jq engine, compiled to WebAssembly, so pipes, select, map, length, keys, group_by, string interpolation, and the rest of the language all work the same as they do on the command line. There is no reduced dialect to learn.

If the expression is not valid jq, or the body is not JSON, the box turns red and shows the error, so you can fix it as you type.

Why it helps

Instead of scrolling a huge payload or writing a script to pull one value, you ask for exactly what you want and read it straight away. It is the quickest way to answer a question about a response, and the filtered output is right there to copy into the next request or a note.

Try it in API Spector

Free and open source. No account needed to use the app.

Keep reading