Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi, I am able to do simple filtering in the Loop XPath query in a tExtractJsonField component. For example, if my input JSON string is:
[
{
"snack": {
"name": "Apple",
"id": 1,
"type": "Fruit"
}
},
{
"snack": {
"name": "Orange",
"id": 2,
"type": "Fruit"
}
},
{
"snack": {
"name": "Broccoli",
"id": 3,
"type": "Vegetable"
}
}
]
I can use this Loop XPath query with a simple filter to return only the fruit snacks:
"/snack[type="Fruit"]"
I want to do something a little more complex. I want to select the Apple if the count of vegetables is <=1, else I want to select the Orange. I tried adding more complex xpath using the count() function but could not get it to work:
"/snack[type="Fruit" and (
(name ="Apple" and count(/snack/type="Vegetable") <= 1) or
(name ="Orange" and count(/snack/type="Vegetable") > 1))]"
Are these more complex filters even supported in Talend?
Thanks in advance for any help.
I figured it out. You can use complex filters like the one I describe. The exact syntax would be:
"/snack[type="Fruit"][
(name ="Apple" and count(//type[text()='Vegetable']) <= 1) or
(name ="Orange" and count(//type[text()='Vegetable']) > 1)]"
I figured it out. You can use complex filters like the one I describe. The exact syntax would be:
"/snack[type="Fruit"][
(name ="Apple" and count(//type[text()='Vegetable']) <= 1) or
(name ="Orange" and count(//type[text()='Vegetable']) > 1)]"