# JSON abfragen

Mit dem Plugin <img src="/files/CKpLoDMZ9pma3PRHVQUk" alt="" data-size="line"> *JSON abfragen* können Sie mit Hilfe sogenannter **JSON-Paths** Daten aus einer JSON Struktur auslesen.

<figure><img src="/files/SicpgXUT7b0zYUT1FEbu" alt="" width="295"><figcaption></figcaption></figure>

## Parameter "JSON"

Wählen Sie eine Variable vom Typ `text` oder `json` aus, die als Quelle für die Abfrage verwendet werden soll.

## Parameter "JSON-Path"

In diesem Eingabefeld legen Sie die Abfrage fest, indem Sie den JSON-Path definieren.

## Parameter "Erstes Ergebnis"

Wählen Sie eine Variable aus, in dem das erste Ergebnis der Abfrage gespeichert werden soll. Nicht jede Abfrage hat mehrere Ergebnisse.

## Parameter "Alle Ergebnisse"

In der Variable vom Typ `collection` werden alle Ergebnisse der Abfrage gespeichert.

## Beispiele

Alle JSON-Paths beziehen sich immer auf folgendes JSON:

```json
{
    "firstName": "John",
    "lastName": "Doe",
    "age": 26,
    "address": {
        "streetAddress": "Naist Street",
        "city": "Nara",
        "postalCode": "630-0192"
    },
    "phoneNumbers": [
        {
            "type": "mobile",
            "number": "0123-4567-8888"
        },
        {
            "type": "home",
            "number": "0123-4567-8910"
        }
    ]
}
```

{% hint style="info" %}
Eine genauere Beschreibung von JSON-Paths finden Sie unter <https://goessner.net/articles/JsonPath/index.html>
{% endhint %}

### Einfache Properties

Mit `$.firstName` wird `John` ausgewählt.

Mit `$.address.postalCode` wird `630-0192` ausgewählt.

### Objekt Properties

Der Ausdruck `$.address` selektiert den gesamten Adressbereich das Objektes. Das Ergebnis der Abfrage ist wieder ein JSON Objekt:

```json
{
  "streetAddress": "Naist Street",
  "city": "Nara",
  "postalCode": "630-0192"
}
```

### Array Index

Die Abfrage `$.phoneNumbers[0].type` liefert als Ergebnis `mobile`. Mit eckigen Klammern kann ein Index angegeben werden.

### Array Slice

Die Abfrage `$.phoneNumbers[1:5:2]` wählt alle Nummern aus dem phoneNumbers-Array aus, deren Index zwischen 1 (einschliesslich) und 5 (ausschliesslich) liegt, mit einer Schrittweite von 2. Das Ergebnis ist:

* Das Element an Index 1
* Das Element an Index 3

Falls die Array-Werte beispielsweise so aussehen:\
`["123", "456", "789", "012", "345", "678"]`\
wäre das Ergebnis:\
`["456", "012"]`.

### Filter

Mit der Abfrage `$.phoneNumbers[?(@.type=='mobile')].number` kann die mobile Telefonnummer ausgelesen werden. Das Ergebnis ist `0123-4567-8888`. Es werden auch Operatoren wie `<`, `>`, `<=`, `>=` und `!=` unterstützt.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.aiaibot.com/robot/plugins/rest-apis-und-json/json-abfragen.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
