Camel JSONPath

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Camel is very popular because of its expression languages. Simple, XPath, OGNL are some of popular ones in the list. JSONPath is a new comer to Apache Camel. You don’t have to covert JSON payloads to XML for further processing, you can directly receive JSON messages and process them directly using JSONPath.

XPath is highly useful while dealing with XML messages, likewise JSONPath for JSON messages. Lets see some sample JSONPath usage for the message below.

JSON Message:

{
"customer": {
"id": "1234",
"name": "john",
"country": "australia",
"metadata": {
"dateOfBirth": "16111989",
"driversLicense": "987654321",
"passportNumber": "345678"
}
}
}

Example 1 – In camel choice 

<choice>

<when>

<jsonpath>$.customer.name</jsonpath>

<touri="mock:end"/>

</when>

</choice>

Example 2 – In camel setHeader 

<setHeaderheaderName="licenseNumber"><jsonpath>$.customer.metadata.driversLicense</jsonpath></setHeader>

 

Some useful JSON online tools:

1. JSONPath expression checker: http://jsonpath.curiousconcept.com

2. XML to JSON converter: http://www.utilities-online.info/xmltojson/#.VKdL4ntlafQ

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail
Gnanaguru Sattanathan

Gnanaguru Sattanathan

I am a Integration developer and a open source enthusiast. My areas of interest includes Enterprise messaging & SOA. Twitter: @tallguru

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>