# merge

## Definition

In a config modifier schema, use `merge` to avoid overwriting all of the properties of an output. This keyword combines multiple objects into one. If objects share the same property name, the value from the last object overwrites the first one.

> **Exclusive keywords**
>
> If `properties`, `if`, `concat`,  `switch`, `pipe`, `merge`, `prefer`, or `items` are present at the same nesting level, only the first keyword listed will run. We recommend not listing these keywords together at the same nesting level. 

## Order of execution

This keyword executes in the following order: 

1. `omit`
2. `constant`
3. `references`
4. `use`
5. `get`
6. Mutually exclusive keywords at this level:
   - `properties` 
   - `if` 
   - `concat` 
   - `switch` 
   - `pipe` 
   - **`merge`** 
   - `prefer` 
   - `items`
7. `default`
8. `plugin`

## Example

You could duplicate the Location resource's `name` to the `description` field. 

**Example: Merge input from initial payload**

```json
  "resource": {
        "description": "Point of Care",
        "mode": "kind",
        "name": "USC-IS",
        "partOf": {
          "reference": "urn:uuid:8041c338-e0d8-4f60-a658-93d89e86f224"
        },
        "physicalType": {
          "coding": [
            {
              "code": "wa",
              "display": "Ward",
              "system": "http://terminology.hl7.org/CodeSystem/location-physical-type"
            }
          ],
          "text": "wa"
        }
  }

```

**Example: Merge selector **

```json
$.entry[?(@.resource.resourceType=="Location")].resource
```

**Example: Config modifier with merge keyword**

```yaml
merge:
  - {}
  - properties:
      description:
        get: name
```

**Example: Merge output**

```json
  "resource": {
        "description": "USC-IS",
        "mode": "kind",
        "name": "USC-IS",
        "partOf": {
          "reference": "urn:uuid:8041c338-e0d8-4f60-a658-93d89e86f224"
        },
        "physicalType": {
          "coding": [
            {
              "code": "wa",
              "display": "Ward",
              "system": "http://terminology.hl7.org/CodeSystem/location-physical-type"
            }
          ],
          "text": "wa"
        }
 }
```

### Alternative solution with @parent

To achieve the same outcome with the `use` keyword and `@parent` variable, try this selector and config modifier instead:

**Example: Alternative selector**

```json
$.entry[?(@.resource.resourceType=="Location")].resource.description
```

**Example: Alternative config modifier**

```yaml
use: '@parent'
get: name
```

[Learn more about use and parent](/how-to-use-redox/change-data-with-config-modifiers/build-a-config-modifier-schema/use).
