Service Virtualization

  • 1.  Best way to validate JSON response against DB values

    Posted Jan 10, 2018 03:16 PM

    Hey Folks,

     

    I have a requirement in my project to validate the JSON response from API against the DB values. JSON response is huge (sometimes 3k lines) and query result is also sometimes more than 5 rows. JSON response also contains complex hierarchy (parent, child, grandchild nodes and so on). Can anyone suggest best way(s) to validate this kind of complex JSON structure against DB values?

     

    Thanks,

    Uttam.



  • 2.  Re: Best way to validate JSON response against DB values
    Best Answer

    Posted Jan 11, 2018 04:39 PM

    Hi Uttam,

     

    Have you tried using JSON path expressions to extract specific values for validation? Typically not everything in the payload has to be validated, but rather a select number of values are validated. In any case, you would need to have all the path expressions defined ahead of time for each scenario so that you can extract the desired values for validation. Perhaps there's an easy way to map the column names to the JSON path, in which case you can dynamically build the path expression based on the DB resultset column names.



  • 3.  Re: Best way to validate JSON response against DB values

    Posted Jan 17, 2018 09:32 AM

    Hi William,

     

    Thanks for your response. Surprisingly, I have a requirement to validate the entire JSON response against the DB values. Earlier, I validated the response by 'filtering' out the required fields and comparing by using 'assertions'. However, since the response is ~2K lines, I cannot afford to have as many assertions for validation. Script maintenance becomes a huge problem. Hence, I was wondering is there any alternate way to validate during this kind of requirement.

     

    Thanks,

    Uttam.