I have a below JSON string from the below i want to find/search criteria in JSON String.
1). To find the Number of keys present. 2). To get the values of given key(
You can also use the JsonPath project provided by REST Assured. This JsonPath project uses Groovy GPath expressions. In Maven you can depend on it like this:
com.jayway.restassured
json-path
2.4.0
Examples:
To get a list of all book categories:
List categories = JsonPath.from(json).get("store.book.category");
Get the first book category:
String category = JsonPath.from(json).get("store.book[0].category");
Get the last book category:
String category = JsonPath.from(json).get("store.book[-1].category");
Get all books with price between 5 and 15:
List
GPath is very powerful and you can make use of higher order functions and all Groovy data structures in your path expressions.