Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Condition data fetch in databank using regular expression

Parasofttoudaya
Parasofttoudaya 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

  • [Deleted User]
    [Deleted User] Posts: 0 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!

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

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

  • kumawatvaishali
    kumawatvaishali 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"
    }

  • jakubiak
    jakubiak Posts: 813 admin

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