cancel
Showing results for 
Search instead for 
Did you mean: 

Checking for Exist in Router

manohar
Contributor

Hi there, I have this pipeline, that I am using to check for a path in Router snap and for somereason, cant make it work.

any pointer on what I am missing?

Basically I am looking for “E1EDPT2” in the json in my router, and I am using'E1EDPT2' in $ in my router. and it just ignores it says its missing.

[
  {
    "IDOC": {
      "E1EDP01": [
        {
          "POSEX": "00010",
          "E1EDPT1": {
            "E1EDPT2": {
              "TDLINE": "Line 10 First test"
            }
          }
        },
        {
          "POSEX": "00020",
          "E1EDPT1": {
            "E1EDPT2": [
              {
                "TDLINE": "This is the second array text being sent."
              },
              {
                "TDLINE": "This is the second line of second array text being sent"
              }
            ]
          }
        }
      ]
    }
  }
][pipeline_2021_08_11 (2).slp|attachment](upload://oZ5dwsBjVnpLIMhkvhbreCtxi8k.slp) (6.9 KB)

Any help is greatly appreciated.

thanks
Manoharpipeline_2021_08_11 (2).slp (6.9 KB)

1 ACCEPTED SOLUTION

del
Contributor III

Yes, I presume so.

So you might change #3 to

jsonPath($,"$.IDOC.E1EDP01[?(@.hasPath('E1EDPT1') && @.E1EDPT1.hasPath('E1EDPT2'))]").length > 0

View solution in original post

4 REPLIES 4

del
Contributor III

@manohar,

I don’t believe the “in” operator will do a deep object search without some creative expression coding.
.
There are probably a dozen ways to accomplish what you want, but based on the object structure you provided, here are optional expressions for your router.

  1. 'E1EDPT2' in $.IDOC.E1EDP01[0].E1EDPT1
    note: this expects only 1 item in the E1EDP01 array, so probably won’t work for you if there’s a potential for multiple items - but I’m providing it so you see the “in” operator works in the specific object path.
  2. jsonPath($,"$.IDOC.E1EDP01[?('E1EDPT2' in @.E1EDPT1)]").length > 0
  3. jsonPath($,"$.IDOC.E1EDP01[?(@.E1EDPT1.hasPath('E1EDPT2'))]").length > 0
    note: 2 & 3 are very similar, but with different jsonPath filter options.

There are likely a number of other options that may be better suited depending on your overall input payload size and structure and potential overhead of the expression. But, hopefully these options will give you ideas to help you on your search.

Also, you probably want to select the “First match” checkbox in the router, otherwise, the documents will flow through to both outputs.

@del thanks for that.

One thing I forgot to mention, when E1EDPT2 is missing then its parent node, E1EDPT1, wont exist either.

if I go with 2 or 3, wont i will get error?

Thanks
Manohar

del
Contributor III

Yes, I presume so.

So you might change #3 to

jsonPath($,"$.IDOC.E1EDP01[?(@.hasPath('E1EDPT1') && @.E1EDPT1.hasPath('E1EDPT2'))]").length > 0

manohar
Contributor

Thanks @del that did the trick.

Manohar