You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Imran Raza Khan <im...@gmail.com> on 2019/09/17 16:46:33 UTC
JSONPath array length validation
I am parsing an json and verify array length like below
from("direct:parseJson")
.setHeader("numberOfBooks").jsonpath("$..books.length()", int.class)
.choice()
.when( simple("${header.numberOfBooks} == '1'"))
.log("One book")
.otherwise()
.log("multiple");
Above Code works, but i am looking for option if we can avoid line 2 with
below
.when( simple("${jsonpath(' $..books.length() ', int.class)} == 1") )
its throwing error
Caused by:
org.apache.camel.language.simple.types.SimpleIllegalSyntaxException:
Unknown function: jsonpath(' $..books.length() ', int.class) == 1 at
location 0
${jsonpath(' $..books.length() ', int.class)} == 1
Re: JSONPath array length validation
Posted by Maruan Sahyoun <sa...@fileaffairs.de>.
Hi,
you're mixing up simple amd jsonpath which is not a function within simple.
Your when statement can be written as .when().jsonpath("$..books.length() == 1")
Take a look at the sample here https://camel.apache.org/components/latest/jsonpath-language.html
BR
Maruan
> I am parsing an json and verify array length like below
>
> from("direct:parseJson")
> .setHeader("numberOfBooks").jsonpath("$..books.length()", int.class)
> .choice()
> .when( simple("${header.numberOfBooks} == '1'"))
> .log("One book")
> .otherwise()
> .log("multiple");
>
> Above Code works, but i am looking for option if we can avoid line 2 with
> below
>
> .when( simple("${jsonpath(' $..books.length() ', int.class)} == 1") )
>
> its throwing error
>
> Caused by:
> org.apache.camel.language.simple.types.SimpleIllegalSyntaxException:
> Unknown function: jsonpath(' $..books.length() ', int.class) == 1 at
> location 0
> ${jsonpath(' $..books.length() ', int.class)} == 1
--