<a id="replacefield"></a>

# Kafka Connect ReplaceField SMT Usage Reference for Confluent Cloud

The `org.apache.kafka.connect.transforms.ReplaceField` Apache Kafka® Single
Message Transform (SMT) filters or renames fields in a record’s Struct
or Map.

## Description

The `ReplaceField` SMT filters or renames fields within a Struct or Map.

Use the concrete transformation type designed for the record key (`org.apache.kafka.connect.transforms.ReplaceField$Key`) or value (`org.apache.kafka.connect.transforms.ReplaceField$Value`).

## Examples

These examples show how to configure and use `ReplaceField`.

### Drop a field

This configuration snippet shows how to use `ReplaceField` to exclude a
field and remove it.

```json
"transforms": "ReplaceField",
"transforms.ReplaceField.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
"transforms.ReplaceField.exclude": "c2"
```

This removes `c2`, transforming the original message as shown here:

`{"c1":22,"c2":"foo"}`

to this result:

`{"c1":22}`

### Rename a field

This configuration snippet shows how to use `ReplaceField` with the
`renames` property.

```json
"transforms": "RenameField",
"transforms.RenameField.type": "org.apache.kafka.connect.transforms.ReplaceField$Value",
"transforms.RenameField.renames": "foo:c1,bar:c2"
```

This replaces the `foo` and `bar` field names with `c1` and `c2`.

Before: `{"foo":22,"bar":"baz"}`

After: `{"c1":22,"c2":"baz"}`

## Properties

| Name      | Description                                                                                             | Type   | Default   | Valid Values                                                                               | Importance   |
|-----------|---------------------------------------------------------------------------------------------------------|--------|-----------|--------------------------------------------------------------------------------------------|--------------|
| `exclude` | Fields to exclude from the resulting Struct or Map. This takes<br/>precedence over the include list.    | List   | “”        | Comma-separated list of fields to exclude.                                                 | Medium       |
| `renames` | Field rename mappings.                                                                                  | List   | “”        | Comma-separated list of colon-delimited renaming pairs, for example<br/>`foo:bar,abc:xyz`. | Medium       |
| `include` | Fields to include. If specified, only the named fields are included<br/>in the resulting Struct or Map. | List   | “”        | Comma-separated list of fields to include.                                                 | Medium       |

## Predicates

Transformations can be configured with *predicates* so that the transformation
is applied only to records which satisfy a condition. You can use predicates in
a transformation chain and, when combined with the [Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Cloud](filter-ak.md#ak-filter), predicates
can conditionally filter out specific records. For details and examples, see [Predicates](filter-ak.md#predicates).
