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

Options

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,253 ✭✭✭
    edited September 2023
    Options

    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.

  • priyagautam
    priyagautam Posts: 10
    Options

    I tried with above path you mentioned but seems not working..its not allowing me to enter xpath in that way

  • priyagautam
    priyagautam Posts: 10
    Options

    @benken_parasoft can you help me with above query? I am getting error for the path you suggested

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

    The XPath you need depends on the structure of the message in question. I was only giving you an example.