field.convert
Convert the type of a field.
Description
Convert takes the field of one type and converts it into another type (e.g. string to integer).
The applicable types are string, int, float and bool. Converting can be done between any combination of types. Note that
booleans will be converted to numeric values 1 (true) and 0 (false). Processor is only applicable to .Key
, .Payload.Before
and .Payload.After
prefixes, and only applicable if said fields contain structured data.
If the record contains raw JSON data, then use the processor json.decode
to parse it into structured data first.
Configuration parameters
Name | Type | Default | Description |
---|---|---|---|
field | string | null | Field is the target field that should be converted.
Note that you can only convert fields in structured data under For more information about the format, see Referencing fields. |
type | string | null | Type is the target field type after conversion, available options are: string, int, float, bool. |
Examples
Convert float
to string
This example takes the float
in field .Key.id
and changes its data type to string
.
Configuration parameters
Name | Value |
---|---|
field | .Key.id |
type | string |
Record difference
Before | After | ||||
1 | { | 1 | { | ||
2 | "position": null, | 2 | "position": null, | ||
3 | "operation": "update", | 3 | "operation": "update", | ||
4 | "metadata": null, | 4 | "metadata": null, | ||
5 | "key": { | 5 | "key": { | ||
6 | - | "id": 123.345 | 6 | + | "id": "123.345" |
7 | }, | 7 | }, | ||
8 | "payload": { | 8 | "payload": { | ||
9 | "before": null, | 9 | "before": null, | ||
10 | "after": { | 10 | "after": { | ||
11 | "foo": "bar" | 11 | "foo": "bar" | ||
12 | } | 12 | } | ||
13 | } | 13 | } | ||
14 | } | 14 | } |
Convert int
to bool
This example takes the int
in field .Payload.After.done
and changes its data type to bool
.
Configuration parameters
Name | Value |
---|---|
field | .Payload.After.done |
type | bool |
Record difference
Before | After | ||||
1 | { | 1 | { | ||
2 | "position": null, | 2 | "position": null, | ||
3 | "operation": "update", | 3 | "operation": "update", | ||
4 | "metadata": null, | 4 | "metadata": null, | ||
5 | "key": { | 5 | "key": { | ||
6 | "id": "123" | 6 | "id": "123" | ||
7 | }, | 7 | }, | ||
8 | "payload": { | 8 | "payload": { | ||
9 | "before": null, | 9 | "before": null, | ||
10 | "after": { | 10 | "after": { | ||
11 | - | "done": 1 | 11 | + | "done": true |
12 | } | 12 | } | ||
13 | } | 13 | } | ||
14 | } | 14 | } |
Convert string
to int
This example takes the string in field .Key.id
and changes its data type to int
.
Configuration parameters
Name | Value |
---|---|
field | .Key.id |
type | int |
Record difference
Before | After | ||||
1 | { | 1 | { | ||
2 | "position": null, | 2 | "position": null, | ||
3 | "operation": "update", | 3 | "operation": "update", | ||
4 | "metadata": null, | 4 | "metadata": null, | ||
5 | "key": { | 5 | "key": { | ||
6 | - | "id": "123" | 6 | + | "id": 123 |
7 | }, | 7 | }, | ||
8 | "payload": { | 8 | "payload": { | ||
9 | "before": null, | 9 | "before": null, | ||
10 | "after": { | 10 | "after": { | ||
11 | "foo": "bar" | 11 | "foo": "bar" | ||
12 | } | 12 | } | ||
13 | } | 13 | } | ||
14 | } | 14 | } |