> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bringits.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Key Mapping With JSONPath

> Extract specific values using JSONPath queries and map them to new keys

The Key Mapping With JSONPath command (Command Type: 1012) extracts specific values from an object using JSONPath queries and maps them to new keys. It is similar to Key Mapping but applies the extraction across the entire data structure using JSONPath.

## Overview

The Key Mapping With JSONPath command provides functionality for:

* Extracting values from deeply nested structures using JSONPath
* Mapping extracted values to new top-level keys
* Transforming complex objects into flat, normalized structures

## Command Type

**Command Type ID:** 1012

## Parameters

| Parameter   | Type                | Description                                                      | Required |
| ----------- | ------------------- | ---------------------------------------------------------------- | -------- |
| **mapping** | Array of KeyMapping | Defines the rules for extracting data and mapping it to new keys | Yes      |

### KeyMapping

| Field    | Type   | Description                                               | Required |
| -------- | ------ | --------------------------------------------------------- | -------- |
| **to**   | string | The new key to which the extracted value will be assigned | Yes      |
| **from** | string | A JSONPath query string to extract the value              | No       |

## Usage Examples

### Extract and Rename Nested Fields

```json theme={null}
{
  "command": "key-mapping-with-json-path",
  "params": {
    "mapping": [
      { "from": "$.data.event.id", "to": "eventId" },
      { "from": "$.data.event.name", "to": "eventName" },
      { "from": "$.data.market.id", "to": "marketId" }
    ]
  }
}
```

### Flatten a Deep Hierarchy

```json theme={null}
{
  "command": "key-mapping-with-json-path",
  "params": {
    "mapping": [
      { "from": "$.response.body.items[0].id", "to": "firstItemId" },
      { "from": "$.response.meta.total", "to": "totalCount" }
    ]
  }
}
```

## Common Use Cases

* **Deep Extraction**: Pull values out of deeply nested JSON paths
* **Flat Output**: Produce flat objects from hierarchical input for sink commands
* **Schema Mapping**: Map arbitrary incoming structures to a fixed output schema

## Related Commands

* [Key Mapping](/stream/commands/parse/key-mapping) - Simpler field renaming without deep path queries
* [Json Path](/stream/commands/parse/json-path) - Extract arrays or multiple values via JSONPath
* [Object Mapper](/stream/commands/parse/object-mapper) - Full object transformation
