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.

Json file validation

priyagautam
priyagautam Posts: 2

I have json file and i want to validate if some column like bank and corresponding value abc is not available in the file.
Can any one suggest me how to do that

Answers

  • benken_parasoft
    benken_parasoft Posts: 1,171 ✭✭✭
    edited September 18

    For example, let's say your JSON contains an array with "column" and "value" like what you mention:

    [
        {
            "column" : "bank",
            "value" : "abc"
        },
        {
            "column" : "school",
            "value" : "123"
        }
    ]
    

    In SOAtest, you can configure a JSON Assertor tool to take this as Input. The tool can accept Input from another test or can reference an external file. One way to accomplish this type of validation would be to create an "Occurrence Assertion". You can first create the assertion on any element you like (doesn't matter). After the assertion is created, click the "Change Element" button, select "Edit XPath manually", then change the XPath to something like "/root/item[column="bank" and value ="abc"]". In the occurrence assertion you can set "Occurrences of element" to 0 if you want to make sure an array item with column="bank" and value ="abc" does not exist.