Condition data fetch in databank using regular expression

ParasofttoudayaParasofttoudaya Posts: 232 ✭✭

Hi Team,
I have a situation to fetch the data based on another data value.

In this below example, i have to fetch the name which id matches with 555

{
"customerName" : "Che",
"AccountType" : "Savings",
"Country" : "Argentina",
"id" : "222"
} ,
{
"customerName" : "Nepolean",
"AccountType" : "Savings",
"Country" : "France",
"id" : "111"
},
{
"customerName" : "Hitler",
"AccountType" : "Savings",
"Country" : "Germany",
"id" : "555"
}

Comments

  • Thomas MooreThomas Moore Posts: 77 admin

    Hi Udaya,

    To do this, you will need to use a JSON Databank with a custom XPath value.

    The XPath you're looking for is going to be something like this:
    /root/customers[1]/item[id="555"]/customerName/text()

    Keep in mind that to make the above JSON valid, I had to wrap it in a root element, hence the "customers" in the XPath :smile:.

    Additionally if you need to, you also have the ability to parameterize the id that the XPath is looking for with ${dataColumn} notation, but note that if you do, you will no longer be able to use the Evaluate XPath option in the databank editor.

    Hope this helps!

  • ParasofttoudayaParasofttoudaya Posts: 232 ✭✭

    Thanks. We were trying by putting double quotes for id :(

  • kumawatvaishalikumawatvaishali Posts: 2

    Hi, how can I make custom xpath if need to fetch based on a key string present.

    For example
    if saving is present in AccountType then only fetch. Occurrence of this is not fixed.
    {
    "customerName" : "Hitler",
    "AccountType" : "XYZ_Savings_XYZ",
    "Country" : "Germany",
    "id" : "555"
    }

  • jakubiakjakubiak Posts: 684 admin

    What about "/root/AccountType[contains(text(),'Savings')]/text()"?

Sign In or Register to comment.