Blueprints

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

About this blueprint

API Inputs

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.

yaml
id: parse_twitter_json_payload
namespace: blueprints

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.core.tasks.log.Log
    message: |
      {{ inputs.json | jq('.meta | has("next_token")') | first }}

  - id: contains
    type: io.kestra.core.tasks.debugs.Return
    format: |
      {{inputs.json["meta"] contains "next_token"}}

  - id: contains_if_else_operator
    type: io.kestra.core.tasks.debugs.Return
    format: |
      {% if inputs.json["meta"] contains "next_token" %} true
        {% else %} false
      {% endif %}

  - id: is_not_null_operator
    type: io.kestra.core.tasks.debugs.Return
    format: |
      {% if inputs.json["meta"]["next_token"] is not null %}
          true
      {% endif %}

Log

Return

More Related Blueprints

New to Kestra?

Use blueprints to kickstart your first workflows.

Get started with Kestra