Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
nfz11
Creator III
Creator III

Complex filter in Loop XPath query in tExtractJSONField

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.

 

Labels (3)
1 Solution

Accepted Solutions
nfz11
Creator III
Creator III
Author

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)]"

 

View solution in original post

1 Reply
nfz11
Creator III
Creator III
Author

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)]"