Submit and vote on feature ideas.

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.

how to validate data via xpath in json assertor

Options
nidhi
nidhi Posts: 10

I have json data in below format and i want to verify that for perticluar source id"67678" amount is -100. i tried to give below path using json asserort and tried converting json to xml and use xpath but that did not work.
/root/item/Ancillary[Id/string()="67678"]/Transaction/detail/Amount
{
"Type": "Mas",
"Date": "2023-09-15",
"Ancillary": {
"Id": "67678"
},
"Transaction": {
"Type": "Order",
"OrderID": "908f2",
"StartDate": "2023-09-15 19:00:20.061539",
"detail": {
"Type": "Future",
"Amount": -100,
"Price": "81.26000000",
"Identifier": {
"Type": "Exchange",
}
},

  {
"Type": "Mas",
"Date": "2023-09-15",
"Ancillary": {
  "Id": "6767887778"
},
"Transaction": {
  "Type": "Order",
  "OrderID": "908f2",
  "StartDate": "2023-09-15 19:9",
  "detail": {
    "Type": "Future",
    "Amount": -300,
    "Price": "81.26000000",
    "Identifier": {
      "Type": "Exchange",
      }
  },]
Tagged:

Answers

  • benken_parasoft
    benken_parasoft Posts: 1,235 ✭✭✭
    Options

    This works just fine for me in the JSON Assertor:

    /root/item[Ancillary/Id/text()="67678"]/Transaction/detail/Amount/string()
    
  • nidhi
    nidhi Posts: 10
    edited October 2023
    Options

    did you select value assertion option? or any other option as i could still see error saying not a valid xpath @banken_parasoft

  • benken_parasoft
    benken_parasoft Posts: 1,235 ✭✭✭
    edited October 2023
    Options

    did you select value assertion option

    Yes, Value assertion or String assertion would work.

    i could still see error saying not a valid xpath

    The XPath is syntactically correct. Can you show the error?