Chapter 23. Extract Field Action


Extract a field from the message body.

The extract field action expects an application/json content type.

The field parameter specifies which field in the JSON to extract. By default, the message body is overridden with the extracted field.

The optional parameter headerOutput specifies whether the extracted field should be stored in a message header named 'CamelKameletsExtractFieldName', leaving the message body untouched.

The optional parameter headerOutputName specifies a custom header name instead of the default 'CamelKameletsExtractFieldName'. This parameter must be used in conjunction with headerOutput. If no headerOutputName parameter is provided, the default 'CamelKameletsExtractFieldName' is used.

The optional parameter strictHeaderCheck enables a strict header name check. If enabled, the action checks if the header output name (custom or default) is already used in the exchange. If so, the extracted field is stored in the message body, if not, the extracted field is stored in the selected header (custom or default).

The headerOutput/headerOutputName/strictHeaderCheck parameters are particulary useful in case you would like to reuse an extracted field as parameter for another header, for example.

23.1. Configuration Options

The following table summarizes the configuration options available for the extract-field-action Kamelet:

Expand
PropertyNameDescriptionTypeDefaultExample

field *

Field

The name of the field to extract

string

  

headerOutput

Header Output

If enable the action will store the extracted field in an header named CamelKameletsExtractFieldName

boolean

False

 

headerOutputName

Header Output Name

A custom name for the header containing the extracted field

string

none

 

strictHeaderCheck

Strict Header Check

If enabled the action will check if the header output name (custom or default) has been used already in the exchange. If so, the extracted field is stored in the message body, if not, the extracted field is stored in the selected header (custom or default).

boolean

False

 

trimField

Trim Field

If enabled we return the Raw extracted field

boolean

False

 

* = Fields marked with an asterisk are mandatory.

23.2. Dependencies

23.2.1. Quarkus dependencies

<dependencies>
  <dependency>
    <groupId>org.apache.camel.kamelets</groupId>
    <artifactId>camel-kamelets-utils</artifactId>
    <version>4.8.5</version>
  </dependency>
  <dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-core</artifactId>
  </dependency>
  <dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-jackson</artifactId>
  </dependency>
  <dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-kafka</artifactId>
  </dependency>
  <dependency>
    <groupId>org.apache.camel.quarkus</groupId>
    <artifactId>camel-quarkus-kamelet</artifactId>
  </dependency>
</dependencies>
Copy to Clipboard Toggle word wrap

23.3. Usage

23.3.1. Camel JBang usage

23.3.1.1. Prerequisites for JBang

  • Install JBang.
  • You have executed the following command:

    jbang app install camel@apache/camel
    Copy to Clipboard Toggle word wrap

23.3.1.2. Running a route with JBang

Suppose you have a file named route.yaml with this content:

- route:
    from:
      uri: "kamelet:timer-source"
      parameters:
        period: 10000
        message: 'test'
      steps:
        - to:
            uri: "kamelet:log-sink"
Copy to Clipboard Toggle word wrap

You can now run it directly through the following command.

camel run route.yaml
Copy to Clipboard Toggle word wrap

23.3.2. Knative Action

You can use the extract-field-action Kamelet as an intermediate step in a Knative binding.

extract-field-action-binding.yaml

apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
  name: extract-field-action-binding
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: timer-source
    properties:
      message: "Hello"
  steps:
  - ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: extract-field-action
    properties:
      field: "The Field"
  sink:
    ref:
      kind: Channel
      apiVersion: messaging.knative.dev/v1
      name: mychannel
Copy to Clipboard Toggle word wrap

23.3.3. Kafka Action

You can use the extract-field-action Kamelet as an intermediate step in a Kafka binding.

extract-field-action-binding.yaml

apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
  name: extract-field-action-binding
spec:
  source:
    ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: timer-source
    properties:
      message: "Hello"
  steps:
  - ref:
      kind: Kamelet
      apiVersion: camel.apache.org/v1
      name: extract-field-action
    properties:
      field: "The Field"
  sink:
    ref:
      kind: KafkaTopic
      apiVersion: kafka.strimzi.io/v1beta1
      name: my-topic
Copy to Clipboard Toggle word wrap

23.4. Kamelets source file

https://github.com/jboss-fuse/camel-kamelets/blob/camel-kamelets-4.10.3-branch/kamelets/extract-field-action.kamelet.yaml

Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat
Back to top