1

In the following (partial)JSON response:

    {
      "costPrices": {
        "3226186": [
          {
            "fromDate": 1420066800000,
            "toDate": null,
            "product": {

I'm trying to access the value of fromDate like this:

    body("costPrices.3226186[0].fromDate", equalTo(1420066800000L))

But when it comes to the number in the path expression it fails, is there some way around this?

java.lang.IllegalArgumentException: Invalid JSON expression: Script1.groovy: 1: unexpected token: 3226186 @ line 1, column 40.

tom redfern
  • 30,562
  • 14
  • 91
  • 126
sjottil
  • 43
  • 6

1 Answers1

1

Your selector is incorrect. With rest-assured's jsonPath, writing

"costPrices.3226186[0].fromDate"

means gather all the 3226186 properties from the objects in the array costPrices and then choose the first one.

In your case, what you want is:

body("costPrices.3226186.fromDate[0]", equalTo(1420066800000L))
Derlin
  • 9,572
  • 2
  • 32
  • 53