# Get Key value

This is pre-built Action located under the **@Generic** Element. It instructs the Avo Assure Client to fetch the value of the specified key value from the JSON input and save the result in the given output variable.

## Syntax

**Input Value**: `<input_json>;<block_component_name>(optional);<block_component_indexes>(optional);<key_name>`

{% hint style="info" %}
**Note**:&#x20;

* Indexing starts from 1.
* Traversal follows the order: Root > Parent Key > Child Key.
* Ensure that the index sequence is correct and properly aligned with the JSON hierarchy.
  {% endhint %}

| Argument                                           | Description                                                                                                                                                                      |
| -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>\<input\_json></p><p>(Required)</p>             | Provide the complete JSON body or input data contains the value to be fetched.                                                                                                   |
| <p>\<block\_component\_name> </p><p>(Optional)</p> | Specifies the hierarchical key path used to navigate from the parent key to the level before the target key. Use (**.**) as a separator between keys. For example: parent.child. |
| <p>\<block\_component\_indexes><br>(Optional)</p>  | Specifies the traversal path using indexes corresponding to each level in the JSON structure, separated by (**,**). For example: 1,2,1.                                          |
| <p>\<key\_name><br>(Required)</p>                  | Specifies the final key from which the value needs to be extracted.                                                                                                              |

**Output Value**:  `<Dynamic Variable>;<Dynamic Variable>(Optional)`

| Argument                                      | Description                                                                 |
| --------------------------------------------- | --------------------------------------------------------------------------- |
| <p> \<Dynamic Variable> </p><p>(Required)</p> | This dynamic variable stores the fetched key value from JSON body.          |
| <p>\<Dynamic Variable> </p><p>(Optional) </p> | This dynamic variable stores the status as **True**, **False** or **None**. |

### **Example:** Extracting Value from JSON Array&#x20;

In this example, we explain how to extract the **first\_name** key value from the JSON input using the **Get Key Value** action.

* **Action**: Get Key Value
* **Input Value**: \<input\_json>;data;1,1;first\_name
  * The first argument (**\<input\_json>**) provides the complete JSON input that contains the value to be retrieved.
  * The second argument (**data**) specifies the parent key path used to navigate within the JSON structure.
  * The third argument (**1,1**) defines the traversal indexes used to access the correct level in the JSON structure.
  * The fourth argument (**first\_name**) specifies the key whose value needs to be extracted.

{% code title="JSON Body" overflow="wrap" expandable="true" %}

```json
{ 
  "success": true, 
  "data": [ 
    { 
      "id": "1", 
      "Title": "Rev", 
      "first_name": "Hilma", 
      "middle_initial": "M", 
      "last_name": "Renz", 
      "suffix": "", 
      "username": "Hilma1", 
      "email_address": "Hilma11@example.com", 
      "phone_number": "(222) 287-7330", 
      "ssn": "037-31-2750", 
      "birth_date": "1986-07-27" 
    } 
  ] 
}
```

{% endcode %}

* **Output Value**: {first\_name}
  * The extracted value (**Hilma**) is stored in the (**{first\_name}**) dynamic variable.
  * If a second output variable is provided, the action returns the execution status as **True** or **False** or **None**:
    * **True**: If the value is successfully retrieved.
    * **False** or **None**: If the key is not found or the traversal path is incorrect.
* **Logical Explanation**: The **Get Key Value** action fetches the value from the **Input Value** column (**\<input\_json>;data;1,1;first\_name**). This action navigates through the JSON structure using the specified key path (**data**) and indexes (**1,1**). It then extracts the value of the **first\_name** key (e.g., Hilma) and stores it in the **{first\_name}** variable.

<details>

<summary><strong>Traversal Explanation (Aligned with Current Example)</strong></summary>

Traversal is performed from the parent key to the child key block using indexes.

To traverse and retrieve the value of the **first\_name** key from the JSON structure, perform the following actions:

1. Start at Root `{ }` .
   1. JSON begins with an object.
   2. To move towards the array `[ ]` under data, use index 1.
2. Navigate to Parent Key (data).
   1. `data` acts as the parent key.
   2. It contains an array `[ ]`.
3. Traverse Inside data Array.
   1. From `{ }` inside data, move into the array `[ ]`.
   2. Select the first object `{ }` > index 1.
4. Reach Child Key.
   1. Inside this object, locate the key `first_name`.
   2. Value present: Hilma

#### Traversal Path

* **Index Path**: 1 > 1
* **Key Path**: data

Traversal is completed from: Parent Key (data) > Child Key (first\_name)

#### Execution Flow

1. Start from root object `{ }`
2. Navigate to parent key **data**
3. Select the 1st element inside the data array
4. Extract the value of **first\_name**

{% hint style="info" %}
**Note**:

* Traversal is performed from parent key to child key block:
  * Use: &#x20;
    * Component name: Used to define key path.
    * Indexes: Used to define traversal path.
  * Use 1 for: &#x20;
    * First element in array.
    * Single object.
      {% endhint %}

</details>

<figure><img src="/files/Eirfo6FzRac4mNhG8Wbg" alt=""><figcaption></figcaption></figure>


---

# 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://docs.avoautomation.com/avo-assure/actions/generic/xml-and-json-operations/get-key-value.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.
