Discussion:
Evaluate JsonPath on string inside a Map
Frank Wein
2017-02-08 10:01:55 UTC
Permalink
Hi all,
I wonder how I can achieve the following: I want to evaluate a JsonPath
predicate in a when() expression on a string, which is inside a
Map/MapMessage. If possible, this should be done with the Camel Java
DSL. The original message should not be modified, I only want to
evaluate the JsonPath expression on this specific spring. It looks to me
I have to combine a simple(body[jsonString]) expression with a
jsonpath(...) expression, but I'm not really sure how to do that. Or is
there another approach which would work better for this type of problem?
Someone can give me a hint?

Best regards
Frank
Frank Wein
2017-02-08 12:16:43 UTC
Permalink
Post by Frank Wein
Hi all,
I wonder how I can achieve the following: I want to evaluate a
JsonPath predicate in a when() expression on a string, which is inside
a Map/MapMessage. If possible, this should be done with the Camel Java
DSL. The original message should not be modified, I only want to
evaluate the JsonPath expression on this specific spring. It looks to
me I have to combine a simple(body[jsonString]) expression with a
jsonpath(...) expression, but I'm not really sure how to do that. Or
is there another approach which would work better for this type of
problem? Someone can give me a hint?
Best regards
Frank
I just found out it's possible to use simple expression in Camel 2.18
with jsonpath: "It's now possible to in-lined Simple
<http://camel.apache.org/simple.html> language expressions in the
JSonPath expression using the simple syntax *|${xxx}|*."

This would probably me, however: Is there also a solution that works
with Camel 2.17.3?

Frank
--
Frank Wein
Forschungsgruppe Netz
Friedrich-Alexander-Universitaet Erlangen-Nuernberg
Regionales Rechenzentrum Erlangen (RRZE)
Martensstrasse 1, 91058 Erlangen, Germany
Tel. +49 9131/85-29983, Fax +49 9131/302941
***@fau.de
www.rrze.fau.de
souciance
2017-02-08 13:05:54 UTC
Permalink
Not sure if this is what you are after but I have done it this way:


.when(PredicateBuilder.isEqualTo(ExpressionBuilder.languageExpression("jsonpath","$.Status"),
"whatyouwantequalto"))

The $.Status is a node in the json string.



--
View this message in context: http://camel.465427.n5.nabble.com/Evaluate-JsonPath-on-string-inside-a-Map-tp5793652p5793669.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Frank Wein
2017-02-09 09:21:33 UTC
Permalink
Post by souciance
.when(PredicateBuilder.isEqualTo(ExpressionBuilder.languageExpression("jsonpath","$.Status"),
"whatyouwantequalto"))
The $.Status is a node in the json string.
--
View this message in context: http://camel.465427.n5.nabble.com/Evaluate-JsonPath-on-string-inside-a-Map-tp5793652p5793669.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Ah thanks, I need to try something in that direction. Actually I
realized now that I (probably) had a wrong understanding how simple(...)
can be used together with jsonpath in Camel 2.18+. I wanted to run a
jsonpath expression on a simple expression, so basically first
simple(...) and then jsonpath(...) (without changing the message body!).
However what's possible in Camel 2.18+ is using a simple expression
inside a jsonpath expression, so you can't actually change what message
the jsonpath expression runs on with the simple DSL.
For now I have temporarily saved the message body in a message header
and restore the message body again after having used the
setBody(simple(...))/when().jsonpath command. But I guess there are
better solutions for this problem.

Best regards

Frank

Loading...