New to Kestra?
Use blueprints to kickstart your first workflows.
Parse a JSON REST API payload in Kestra and check whether a key exists using jq filters, the contains operator, and is not null Pebble expressions.
Working with REST APIs almost always means parsing JSON, and a recurring task is checking whether a specific key is present in the payload before you act on it. A classic example is pagination: a Twitter (X) API response includes a next_token field only when more pages remain, so your flow needs to detect that key reliably to decide whether to keep fetching. This blueprint shows three idiomatic ways to test for a key in a JSON object using Kestra expressions, so you can pick the style that reads best for your pipeline and branch on the result.
The flow defines a single json input of type JSON whose default payload mimics a paginated API response with a meta object containing next_token, oldest_id, newest_id, and result_count. Four tasks then evaluate that payload:
jq_filter is an io.kestra.plugin.core.log.Log task that runs the jq filter .meta | has("next_token") and logs whether the key exists.contains is an io.kestra.plugin.core.debug.Return task that uses the Pebble contains operator: {{ inputs.json["meta"] contains "next_token" }}.contains_if_else_operator is another io.kestra.plugin.core.debug.Return task that wraps contains in an {% if %} / {% else %} block to return an explicit true or false.is_not_null_operator is a final io.kestra.plugin.core.debug.Return task that checks {% if inputs.json["meta"]["next_token"] is not null %} for a value-based test.jq filter, the contains operator, and an is not null test.jq filtering.A raw API or a cron scheduler can fetch JSON but cannot express conditional logic over the response. Kestra lets you parse payloads inline with declarative YAML, branch on the result, and chain follow-up tasks (loop until next_token is absent, fan out per record, or alert on missing fields). You gain event triggers, automatic retries on transient API failures, and full execution lineage over every parse, none of which the API itself provides.
This flow references no secrets. When you point it at a live API behind authentication, store the token as a secret (for example {{ secret('API_TOKEN') }}) rather than hardcoding it.
json payload to see all three checks return true.next_token and re-run to watch the checks flip to false.io.kestra.plugin.core.http.Request task that fetches a live API response.next_token is present.if condition to skip or trigger downstream tasks.