This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new d177639c666c CAMEL-22641: Update jsonpath docs
d177639c666c is described below

commit d177639c666c4399f594c27ccbe6d8720731a1d2
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Dec 9 13:26:53 2025 +0100

    CAMEL-22641: Update jsonpath docs
---
 .../src/main/docs/jsonpath-language.adoc           | 24 +++++++++++++++++-----
 .../jsonpath/JsonPathTransformHeaderNameTest.java  |  4 +---
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc 
b/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc
index 08f9d30a4cc2..a0b46ecb13e3 100644
--- a/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc
+++ b/components/camel-jsonpath/src/main/docs/jsonpath-language.adoc
@@ -342,30 +342,44 @@ If a book array contains only one book, it will be 
converted into a Book object.
 === Using header as input
 
 By default, JSONPath uses the message body as the input source. However, you 
can also use a header as input
-by specifying the `headerName` option.
+by specifying the `source` option.
 
 For example, to count the number of books from a JSON document that
 was stored in a header named `books` you can do:
 
 [source,java]
 ----
+var jp = expression().jsonpath("$..store.book.length()").resultType(int.class)
+        .source("header:books").end();
+
 from("direct:start")
-    .setHeader("numberOfBooks")
-        .jsonpath("$..store.book.length()", false, int.class, "books")
+    .setHeader("numberOfBooks", jp)
+    .to("mock:result");
+----
+
+And you can also inline the expression:
+
+[source,java]
+----
+from("direct:start")
+    .setHeader("numberOfBooks", 
expression().jsonpath("$..store.book.length()").resultType(int.class)
+            .source("header:books").end())
     .to("mock:result");
 ----
 
 In the `jsonpath` expression above we specify the name of the header as 
`books`,
 and we also told that we wanted the result to be converted as an integer by 
`int.class`.
 
-The same example in XML DSL would be:
+TIP: You can also use `variable:` as source prefix to refer to an Exchange 
variable instead of a header.
+
+The same example in XML DSL would be easier to do:
 
 [source,xml]
 ----
 <route>
   <from uri="direct:start"/>
   <setHeader name="numberOfBooks">
-    <jsonpath headerName="books" 
resultType="int">$..store.book.length()</jsonpath>
+    <jsonpath source="header:books" 
resultType="int">$..store.book.length()</jsonpath>
   </setHeader>
   <to uri="mock:result"/>
 </route>
diff --git 
a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathTransformHeaderNameTest.java
 
b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathTransformHeaderNameTest.java
index dcf3a187a120..6b3d36ee3b23 100644
--- 
a/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathTransformHeaderNameTest.java
+++ 
b/components/camel-jsonpath/src/test/java/org/apache/camel/jsonpath/JsonPathTransformHeaderNameTest.java
@@ -33,10 +33,8 @@ public class JsonPathTransformHeaderNameTest extends 
CamelTestSupport {
         return new RouteBuilder() {
             @Override
             public void configure() {
-                var jp = 
expression().jsonpath().expression("$.store.book[*].author").source("header:myHeader").end();
-
                 from("direct:start")
-                        .transform(jp)
+                        
.transform(expression().jsonpath("$.store.book[*].author").source("header:myHeader").end())
                         .to("mock:authors");
             }
         };

Reply via email to