Blueprints

Check if a given key exists in a JSON REST API payload

Source

yaml
id: parse-twitter-json-payload
namespace: company.team
inputs:
  - id: json
    type: JSON
    defaults: |
      {
        "meta": {
          "oldest_id": "1197549579035496449",
          "newest_id": "1255542797765013504",
          "result_count": 100,
          "next_token": "7140k9",
          "previous_token": "77qp8"
        }
      }
tasks:
  - id: jq_filter
    type: io.kestra.plugin.core.log.Log
    message: |
      {{ inputs.json | jq('.meta | has("next_token")') | first }}
  - id: contains
    type: io.kestra.plugin.core.debug.Return
    format: |
      {{inputs.json["meta"] contains "next_token"}}
  - id: contains_if_else_operator
    type: io.kestra.plugin.core.debug.Return
    format: |
      {% if inputs.json["meta"] contains "next_token" %} true
        {% else %} false
      {% endif %}
  - id: is_not_null_operator
    type: io.kestra.plugin.core.debug.Return
    format: |
      {% if inputs.json["meta"]["next_token"] is not null %}
          true
      {% endif %}

About this blueprint

Inputs API

Its common to receive a payload from a REST API and check if a given key exists in a JSON payload. This flow demonstrates multiple ways of accomplishing that — a JQuery filter, a contains operator, and an is not null operator.

Check the Expressions documentation for more examples.

Log

Return

Return

Return

More Related Blueprints

New to Kestra?

Use blueprints to kickstart your first workflows.

Get started with Kestra