You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Michael Joyner <mi...@gmail.com> on 2018/05/22 15:12:27 UTC
Content based router with JSONPATH
Hi everyone.
This might be a easy question, I have been fighting with it for a couple
hours. I have a JSON array that is sent to a splitter to process each
JSON object.
HERE'S SAMPLE JSON BODY:
{
"id": "2b144adc-1af4-1446-e22a-58b367d22272",
"module_name": "Accounts",
"name_value_list": {
"name": {
"name": "name",
"value": "Tri-State Medical Corp"
},
"account_type": {
"name": "account_type",
"value": "Customer"
},
"industry": {
"name": "industry",
"value": "Environmental"
},
"annual_revenue": {
"name": "annual_revenue",
"value": ""
},
"rating": {
"name": "rating",
"value": ""
}
}
}
Here's my route, I can't seem to find the right syntax to get jsonpath()
to evaluate like XPATH. It wont run because the JSON path string isn't
happy.
from("file:///opt/talend/esb/talend-esb-csv-to-xml/data1?noop=true&autoCreate=true&flatten=false&fileName=accounts.json)
.split()
.jsonpath("$.entry_list[*]")
.choice()
.when().jsonpath(
*"**$.name_value_list.account_type.value = 'Customer'*" )
.log("CUSTOMER \n ${body}")
.when().jsonpath(
"*$.name_value_list.account_type.value = 'Vendor'*" )
.log("VENDOR\n ${body}")
Re: Content based router with JSONPATH (Solution found)
Posted by Michael Joyner <mi...@gmail.com>.
I found JSON path statement to query the JSON object:
when.jsonpath("$.name_value_list.account_type[?(@.value=='Customer')]")
On 05/22/2018 08:12 AM, Michael Joyner wrote:
>
> Hi everyone.
>
> This might be a easy question, I have been fighting with it for a
> couple hours. I have a JSON array that is sent to a splitter to
> process each JSON object.
>
> HERE'S SAMPLE JSON BODY:
>
> {
> "id": "2b144adc-1af4-1446-e22a-58b367d22272",
> "module_name": "Accounts",
> "name_value_list": {
> "name": {
> "name": "name",
> "value": "Tri-State Medical Corp"
> },
> "account_type": {
> "name": "account_type",
> "value": "Customer"
> },
> "industry": {
> "name": "industry",
> "value": "Environmental"
> },
> "annual_revenue": {
> "name": "annual_revenue",
> "value": ""
> },
> "rating": {
> "name": "rating",
> "value": ""
> }
>
> }
> }
>
> Here's my route, I can't seem to find the right syntax to get
> jsonpath() to evaluate like XPATH. It wont run because the JSON path
> string isn't happy.
>
> from("file:///opt/talend/esb/talend-esb-csv-to-xml/data1?noop=true&autoCreate=true&flatten=false&fileName=accounts.json)
> .split()
> .jsonpath("$.entry_list[*]")
>
> .choice()
>
> .when().jsonpath(
> *"**$.name_value_list.account_type.value = 'Customer'*" )
> .log("CUSTOMER \n ${body}")
>
> .when().jsonpath(
> "*$.name_value_list.account_type.value = 'Vendor'*" )
> .log("VENDOR\n ${body}")
>