Optimum way to verify complex JSON response

196 views
Skip to first unread message

80Vikram

unread,
Nov 28, 2017, 6:53:39 AM11/28/17
to REST assured
Hi All,

I need to verify JSON response as below

- What is optimal way of verifying each of the key : value pair ? 

- Also how do you maintain expected test data to verify against actual data ?

Thanks in advance.

{
  "gridFactors": {
    "leadId": "xxxx",
    "netIncome": xxxx,
    "downPayment": null,
    "loanDuration": null
  },
  "grid": {
    "state": "PO",
    "expirationDate": null,
    "offers": [
      {
        "duration": 12,
        "recommendation": false,
        "steps": [
          {
            "interestRateEffective": 3.99,
            "interestRateNominal": 3.92,
            "interestRate2of3Effective": 4.15,
            "interestRate2of3Nominal": 4.07,
            "maxAmount": 1099,
            "recommendation": false,
            "standardOffer": true
          },
          {
            "interestRateEffective": 2.99,
            "interestRateNominal": 2.95,
            "interestRate2of3Effective": 3.59,
            "interestRate2of3Nominal": 3.53,
            "minAmount": 1100,
            "maxAmount": 6000,
            "recommendation": false,
            "standardOffer": false
          },
          ....
        ]
      },
      {
        "duration": 24,
        "recommendation": false,
        "steps": [
          {
            "interestRateEffective": 3.99,
            "interestRateNominal": 3.92,
            "interestRate2of3Effective": 4.15,
            "interestRate2of3Nominal": 4.07,
            "maxAmount": 1099,
            "recommendation": false,
            "standardOffer": true
          },
          {
            "interestRateEffective": 2.99,
            "interestRateNominal": 2.95,
            "interestRate2of3Effective": 3.59,
            "interestRate2of3Nominal": 3.53,
            "minAmount": 1100,
            "maxAmount": 5100,
            "recommendation": false,
            "standardOffer": false
          },
......

Johan Haleby

unread,
Nov 28, 2017, 7:02:08 AM11/28/17
to rest-a...@googlegroups.com
Imho there's no "optimal way", it depends :) If the context you're working with is small and simple and you feel like there's no need for other tests than REST API tests you could use JsonSchema validation or just standard Hamcrest. But if the JSON is large then I'd probably create some other kinds of tests to verify the logic/behavior (e.g. that interestRateEffective is calculated correctly) and then use json schema validation for the structure (i.e. ignore the actual value). Other than that I'd probably create some sanity tests with using Hamcrest matchers but I wouldn't validate all properties (again depending on use case).

Regards,
/Johan

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

80Vikram

unread,
Nov 28, 2017, 7:10:48 AM11/28/17
to REST assured
Hi Johan,

Thanks a ton for detailed clarification.

Regards,
Vikram
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages