cancel
Showing results for 
Search instead for 
Did you mean: 

Selecting an entity from an Array

arvindnsn
Contributor

Hello,

From the below Array, I am trying to get only the “error” entity which will be in any one element or multiple elements. I tried using $.result.find(x => x.name == ‘error’) and $.result.map(x => x.name == ‘error’), but in vain. I am trying to find a solution using expression and not using the splitter. Really appreciate any help here. Thanks in advance.

"result": [
  {
    "execution": "0",
    "sqlStatement": "BEGIN;",
    "count": -1
  },
  {
    "execution": "1",
    "sqlStatement": "CREATE  OR REPLACE TABLE POS_DB.POS_EDW.TEST_CLONE POS_DB.POS_EDW.TEST_FS",
    "error": "net.snowflake.client.jdbc.SnowflakeSQLException: SQL compilation error:\nObject 'POS_DB.POS_EDW.GUEST_CHECKS_FS' does not exist or not authorized.",
  },
  {
    "execution": "2",
    "sqlStatement": "ROLLBACK;",
    "count": -1
  }
]
1 ACCEPTED SOLUTION

Aleksandar_A
Contributor III

Hi @arvindnsn,

You can try to filter out documents that have “error” keys, and later on to split them using JSON Splitter Snap.

$result.filter(x => x.hasPath("error"))

Let me know if this helps you.

BR,
Aleksandar.

View solution in original post

2 REPLIES 2

Aleksandar_A
Contributor III

Hi @arvindnsn,

You can try to filter out documents that have “error” keys, and later on to split them using JSON Splitter Snap.

$result.filter(x => x.hasPath("error"))

Let me know if this helps you.

BR,
Aleksandar.

Yes, I was able to retrieve just the element that has “error” entity and then use the splitter to flatten that Array element.

Thank you for the solution,