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

# Kafka Connect ReplaceField SMT Usage Reference for Confluent Platform

The `ReplaceField` SMT (`org.apache.kafka.connect.transforms.ReplaceField`)
filters or renames fields within an Apache Kafka® record’s Struct or Map.

## Description

Filter or rename 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`).

For the Confluent version that also supports nested fields, see
[ReplaceField (Confluent)](replacefield-confluent.md#confluent-replacefield).

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

## 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 will be included<br/>in the resulting Struct or Map.                                                              | list    | “”        | Comma-separated list of fields to include.                                                  | medium       |
| `replace.null.with.default` | Specifies whether to replace null fields with their defined default<br/>values. When set to `true`, the default value is applied. Otherwise,<br/>the field remains null. | boolean | `true`    | `true` or `false`                                                                           | medium       |

## 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"}`

## Predicates

Configure transformations with predicates to ensure they process only records
that satisfy a particular condition. You can also use predicates in a
transformation chain with the [Kafka Connect Filter (Kafka) SMT Usage Reference for Confluent Platform](filter-ak.md#ak-filter) to conditionally filter specific
records. For more information, see [Predicates](filter-ak.md#predicates).
