# Transformers

Connectors support Mapping and Service transformers for modifying messages as they flow through a connector.

***

## Mapping transformer

The mapping transformer uses [Bloblang](/platform/1.14/connectors/bloblang.md), a powerful declarative language for data transformation.

### Configuration

| Name       | Type   | Optional | Secret | Description                                     |
| ---------- | ------ | -------- | ------ | ----------------------------------------------- |
| sourcecode | string | no       | no     | Bloblang mapping code that transforms messages. |

### Examples

**Add fields to a message:**

```
mapping:

  sourcecode: |

    root = this

    root.id = uuid_v4()

    root.processed_at = timestamp_unix()
```

**Restructure a message:**

```
mapping:

  sourcecode: |

    root = this

    root.user = {

      "name": this.firstName + " " + this.lastName,

      "email": this.email.lowercase()

    }

    root.metadata = {

      "source": "connector",

      "version": 1

    }
```

**Handle missing values:**

```
mapping:

  sourcecode: |

    root = this

    root.name = this.name.or("Anonymous")

    root.score = this.score.catch(0)
```

**Delete sensitive fields:**

```
mapping:

  sourcecode: |

    root = this

    root.password = deleted()

    root.ssn = deleted()
```

See the [Bloblang Reference](/platform/1.14/connectors/bloblang.md) for the complete language documentation.

***

## Service transformer

The service transformer sends each message to a NATS service and uses the response as the transformed message.

### Configuration

| Name     | Type   | Optional | Secret | Description                                                      |
| -------- | ------ | -------- | ------ | ---------------------------------------------------------------- |
| endpoint | string | no       | no     | The NATS subject where the service receives requests.            |
| timeout  | string | yes      | no     | Maximum time to wait for a response. The value defaults to `5s`. |

### Example

```
service:

  endpoint: 'transform.enrich-user'

  timeout: '10s'
```
