# Get a JSON's Thing

## Overview

This procedure extracts a specific element or elements from a JSON structure based on the specified "thing" (field name or path). The thing can be specified with additional adjectives to refine the search within the JSON structure. It supports both simple field access and nested path traversal using dot notation (e.g., `address.city`) or possessive syntax (e.g., `address's city`). When the JSON is an array, it can extract values from multiple objects.

## Input

| Concept | Type   | Description                                                                                             | Required | Default |
| ------- | ------ | ------------------------------------------------------------------------------------------------------- | -------- | ------- |
| json    | json   | The JSON structure from which the thing is to be extracted                                              | Yes      | N/A     |
| thing   | string | The specific element or elements to extract from the JSON (can include adjectives to refine the search) | Yes      | N/A     |

## Output

| Concept | Description                                                                                                                |
| ------- | -------------------------------------------------------------------------------------------------------------------------- |
| result  | The extracted element or elements from the JSON structure. If multiple elements are extracted, they are returned as a list |

## Examples

### 1. Getting a simple field from a JSON object

This example extracts the "name" field from a JSON object.

```kog
get the json
get the json's name
```

### 2. Getting a field with an adjective

This example extracts the "first name" field from a JSON object. If the JSON is an array, it returns the "name" field from the first element.

```kog
get the json
get the json's first name
```

### 3. Getting nested fields using dot notation

This example extracts the "city" field from the nested "address" object using dot notation.

```kog
get the json
get the json's address.city
```

### 4. Getting nested fields using possessive syntax

This example extracts the "city" field from the nested "address" object using possessive syntax.

```kog
get the json
get the json's address's city
```

### 5. Getting fields with spaces

This example extracts a field named "address city" (a single key with a space in it).

```kog
get the json
get the json's address city
```

### 6. Getting fields from a JSON array

This example shows how to extract fields from an array of JSON objects. When the JSON is an array like `[{"Product Name": "P854282R COMP", "Price": "$53.00"}, {"Product Name": "F854734 COMP", "Price": "$34.95"}]`, you can use ordinals like "first" and "second" to access specific elements.

```kog
get the term as a json
get the json's Prices
get the json's first Price
get the json's first Product Name
get the json's second Quantity
```

### 7. Getting deeply nested fields

This example demonstrates accessing deeply nested fields using multiple possessive syntax. For a JSON structure with customers, orders, and order details, this navigates through multiple levels to extract the id field.

```kog
get the foo's first order's first detail's id
```

### 8. Handling fields with camelCase or special naming

This example shows accessing fields with camelCase naming conventions like "threadId", "historyId", and "sizeEstimate".

```kog
get the email's threadId
get the email's historyId
get the email's sizeEstimate
```
