0

I want to print the value of "isbn" the in below JSON body using jayway.restassured.path.json.JsonPath and not by any other library. As you can see below, there is no name present for the given JSON array which is having only 1 element.

  [
     {
        "isbn":"1849830547",
        "title":"American Assassi",
        "author":"Vince Flyn",
        "price":7.99
     }
  ]

Note: Consider I am already having the above JSON output in a String body and I am creating a JSONpath object as below JsonPath jsonPath = new JsonPath(body);

I have tried below things

String isbn= jsonPath.get("$[0].isbn"); 
String isbn= jsonPath.get("[0].isbn"); 
String isbn= jsonPath.get("isbn"); 
String isbn= jsonPath.get("$.isbn");

And none of the above worked for me

JeffC
  • 22,180
  • 5
  • 32
  • 55
Brenda
  • 7
  • 1
  • 7
  • 1
    Hi, have you tried to access the first element of the array directly, e.g. something along the lines of $[0].isbn. – Mo A Jan 16 '19 at 12:49
  • 2
    What's the precise problem you're having? What have you tried so far? – alezvic Jan 16 '19 at 12:52
  • I have tried below things String isbn= jsonPath.get("$[0].isbn"); String isbn= jsonPath.get("[0].isbn"); String isbn= jsonPath.get("isbn"); And none of the above worked for me. – Brenda Jan 16 '19 at 13:21
  • 1
    Removed the [Selenium] tag since this has nothing to do with Selenium. – JeffC Jan 16 '19 at 15:38

0 Answers0