<commit_before>[[JSonPath-JSonPath]]
JSonPath
~~~~~~~~

*Available as of Camel 2.13*

Camel supports https://code.google.com/p/json-path/[JSonPath] to allow
using link:expression.html[Expression] or link:predicate.html[Predicate]
on json messages.

[source,java]
-----------------------------------------------------
from("queue:books.new")
  .choice()
    .when().jsonpath("$.store.book[?(@.price < 10)]")
      .to("jms:queue:book.cheap")
    .when().jsonpath("$.store.book[?(@.price < 30)]")
      .to("jms:queue:book.average")
    .otherwise()
      .to("jms:queue:book.expensive")
-----------------------------------------------------

[[JSonPath-Options]]
JSonPath Options
^^^^^^^^^^^^^^^^


// language options: START
The JSonPath language supports 4 options which are listed below.



{% raw %}
[width="100%",cols="2,1m,1m,6",options="header"]
|=======================================================================
| Name | Default | Java Type | Description
| resultType |  | String | Sets the class name of the result type (type from output)
| suppressExceptions | false | Boolean | Whether to suppress exceptions such as PathNotFoundException.
| allowSimple | true | Boolean | Whether to allow in inlined simple exceptions in the json path expression
| trim | true | Boolean | Whether to trim the value to remove leading and trailing whitespaces and line breaks
|=======================================================================
{% endraw %}
// language options: END



[[JSonPath-UsingXMLconfiguration]]
Using XML configuration
^^^^^^^^^^^^^^^^^^^^^^^

If you prefer to configure your routes in your link:spring.html[Spring]
XML file then you can use link:jsonpath.html[JSonPath] expressions as
follows

[source,xml]
-------------------------------------------------------------------------
  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="direct:start"/>
      <choice>
        <when>
          <jsonpath>$.store.book[?(@.price &lt; 10)]</jsonpath>
          <to uri="mock:cheap"/>
        </when>
        <when>
          <jsonpath>$.store.book[?(@.price &lt; 30)]</jsonpath>
          <to uri="mock:average"/>
        </when>
        <otherwise>
          <to uri="mock:expensive"/>
        </otherwise>
      </choice>
    </route>
  </camelContext>
-------------------------------------------------------------------------

[[JSonPath-Syntax]]
Syntax
^^^^^^

See the https://code.google.com/p/json-path/[JSonPath] project page for
further examples.

[[JSonPath-Suppressexceptions]]
Suppress exceptions
~~~~~~~~~~~~~~~~~~~

*Available as of Camel 2.16*

By default jsonpath will throw an exception if the json payload does not
have a valid path accordingly to the configured jsonpath expression. In
some use-cases you may want to ignore this in case the json payload
contains optional data. Therefore you can set the option
suppressExceptions to true to ignore this as shown:
<commit_msg>CAMEL-10646: Add docs<commit_after>[[JSonPath-JSonPath]]
JSonPath
~~~~~~~~

*Available as of Camel 2.13*

Camel supports https://code.google.com/p/json-path/[JSonPath] to allow
using link:expression.html[Expression] or link:predicate.html[Predicate]
on json messages.

[source,java]
-----------------------------------------------------
from("queue:books.new")
  .choice()
    .when().jsonpath("$.store.book[?(@.price < 10)]")
      .to("jms:queue:book.cheap")
    .when().jsonpath("$.store.book[?(@.price < 30)]")
      .to("jms:queue:book.average")
    .otherwise()
      .to("jms:queue:book.expensive")
-----------------------------------------------------

[[JSonPath-Options]]
JSonPath Options
^^^^^^^^^^^^^^^^


// language options: START
The JSonPath language supports 4 options which are listed below.



{% raw %}
[width="100%",cols="2,1m,1m,6",options="header"]
|=======================================================================
| Name | Default | Java Type | Description
| resultType |  | String | Sets the class name of the result type (type from output)
| suppressExceptions | false | Boolean | Whether to suppress exceptions such as PathNotFoundException.
| allowSimple | true | Boolean | Whether to allow in inlined simple exceptions in the json path expression
| trim | true | Boolean | Whether to trim the value to remove leading and trailing whitespaces and line breaks
|=======================================================================
{% endraw %}
// language options: END



[[JSonPath-UsingXMLconfiguration]]
Using XML configuration
^^^^^^^^^^^^^^^^^^^^^^^

If you prefer to configure your routes in your link:spring.html[Spring]
XML file then you can use link:jsonpath.html[JSonPath] expressions as
follows

[source,xml]
-------------------------------------------------------------------------
  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="direct:start"/>
      <choice>
        <when>
          <jsonpath>$.store.book[?(@.price &lt; 10)]</jsonpath>
          <to uri="mock:cheap"/>
        </when>
        <when>
          <jsonpath>$.store.book[?(@.price &lt; 30)]</jsonpath>
          <to uri="mock:average"/>
        </when>
        <otherwise>
          <to uri="mock:expensive"/>
        </otherwise>
      </choice>
    </route>
  </camelContext>
-------------------------------------------------------------------------

[[JSonPath-Syntax]]
Syntax
^^^^^^

See the https://code.google.com/p/json-path/[JSonPath] project page for
further examples.

[[JSonPath-SupportedType]]
Supported message body types
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Camel JSonPath supports message body using the following types:

{% raw %}
[width="100%",cols="3m,7",options="header"]
|=======================================================================
| Type | Comment
| File | Reading from files
| String | Plain strings
| Map | Message bodies as `java.util.Map` types
| List | Message bodies as `java.util.List` types
| POJO | *Optional* If Jackson is on the classpath, then camel-jsonpath
  is able to use Jackson to read the message body as POJO and convert to `java.util.Map`
  which is supported by JSonPath. For example you can add `camel-jackson` as dependency to include Jackson.
| InputStream | If none of the above types matches, then Camel will attempt to read the message body as an `java.io.InputStream`.
|=======================================================================
{% endraw %}

If a message body is of unsupported type then an exception is thrown by default, however you
can configure JSonPath to suppress exceptions (see below)


[[JSonPath-Suppressexceptions]]
Suppress exceptions
~~~~~~~~~~~~~~~~~~~

*Available as of Camel 2.16*

By default jsonpath will throw an exception if the json payload does not
have a valid path accordingly to the configured jsonpath expression. In
some use-cases you may want to ignore this in case the json payload
contains optional data. Therefore you can set the option
suppressExceptions to true to ignore this as shown:

{'fraction_non_alphanumeric': 0.25900612273956997, 'fraction_numerical': 0.007689021785561726, 'mean_word_length': 3.0114220445459736, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 43, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1563361', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1819, 'n_words': 601}