Feel Expression to filter list of complex objects

I have a list of “components” complex object that contain complex objects. Pl see the structure below.Using DMN Feel Expression (or FEEL For loop or FEEL Context or any other technique in DMN)
I want to FILTER and retrieve the list of
Components
WHERE Components[code.coding[1].code=“CodingValue-A”]

{
Components [
       {
           code: {
                  coding: [
                          {
                              system: "CodingSystem-A",
                              code: "CodingValue-A"
                          }
                  ]              
           },
          concept {
                   coding: [
                          {
                              system: "ConceptSystem-A",
                              code: "ConceptValue-A"
                          }
                  ]        

          }
       },
       {
           code: {
                  coding: [
                          {
                              system: "CodingSystem-B",
                              code: "CodingValue-B"
                          }
                  ]              
           },
          concept {
                   coding: [
                          {
                              system: "ConceptSystem-B",
                              code: "ConceptValue-B"
                          }
                  ]        

          }
       }
]
}

Hi @Mallesh_Nagothi, :wave:

This is related to the issue: FEEL Expression evaluates to null, instead of ignoring missing element in JSON · Issue #572 · camunda/feel-scala · GitHub

The problem is that not all items in “Components” have an entry “code”. As a result, the evaluation fails.

Good news: this issue is fixed in the upcoming version Camunda 8.3. :tada:

As a workaround, you need to add a null-check in the filter condition.

Best regards,
Philipp

I’m sorry if my example JSON was incorrect. I will have “code” entries in the side “Components” array. I just need to filter the Components Array by the given condition, ie components[code.coding[code=“CodingValue-A”]] (sorry this is syntactically not valid, just for demonstration of my issue)

and expecting output to filter out everything in the Components array and return
Components [
{
code: {
coding: [
{
system: “CodingSystem-A”,
code: “CodingValue-A”
}
]
},
concept {
coding: [
{
system: “ConceptSystem-A”,
code: “ConceptValue-A”
}
]

      }
   }]

DMN_List_Testing.dmn (6.7 KB)

Solved it by flattening the component array::

flatten(tComponents)[code.coding.code=“Code-B”]

Can someone validate my solution? Do I need to do any null checks?

To validate your solution, we need to clarify the input first. Is this your JSON input?

{
   "Components":[
      {
         "code":{
            "coding":[
               {
                  "system":"CodingSystem-A",
                  "code":"CodingValue-A"
               }
            ]
         },
         "concept":{
            "coding":[
               {
                  "system":"ConceptSystem-A",
                  "code":"ConceptValue-A"
               }
            ]
         }
      },
      {
         "code":{
            "coding":[
               {
                  "system":"CodingSystem-B",
                  "code":"CodingValue-B"
               }
            ]
         },
         "concept":{
            "coding":[
               {
                  "system":"ConceptSystem-B",
                  "code":"ConceptValue-B"
               }
            ]
         }
      }
   ]
}

That’s the correct input.

Good. :+1:

If I evaluate the expression with Camunda 8.3

flatten(Components)[code.coding.code="CodingValue-B"]

Then it returns an empty list. The problem is that “coding” is of type list.

You could fix the problem by using the function list contains(). If I evaluate the expression

Components[list contains(code.coding.code, "CodingValue-B")]

Then it returns the following result:

[
   {
      "code":{
         "coding":[
            {
               "system":"CodingSystem-B",
               "code":"CodingValue-B"
            }
         ]
      },
      "concept":{
         "coding":[
            {
               "system":"ConceptSystem-B",
               "code":"ConceptValue-B"
            }
         ]
      }
   }
]

Does this match the expected result?


:warning: If you use Camunda 8.2 or a previous version, you need to add a null-check. For example:

Components[code.coding.code != null and list contains(code.coding.code, "CodingValue-B")]

It worked well. Thank you!
Would you please help to write a list not contain feel expression?

Components[not(list contains(code.coding.code, “CodingValue-B”))] is not working.