

https://mvnrepository.co m/artifact/org.json/json/2 0210307
get org.json from maven
add below dependency to your maven:
<!--
https://mvnrepository.com/artifact/org.json/js
on -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
Now import these:
//import these
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;
Now you can convert a json string to json object just like that:
//now you can convert string to array and
object without having complicated maps
and objects
try {
JSONArray jsonArray = new
JSONArray("[1,2,3,4,5]");
//you can give entire jsonObject here
JSONObject jsonObject = new
JSONObject("{\"name\": [\"praveen\"]}");
System.out.println("outputarray: " +
jsonArray.toString(2));
System.out.println("outputObject: " +
jsonObject.toString(2));
} catch (JSONException err) {
System.out.println("Error: " +
err.toString());
}
Sending request as
Response response = RestAssured.given() .header("Content-type", "application/json") .and() .body("{\r\n" + " \"name\": \"praveen\",\r\n" + " \"job\": \"leader\"\r\n" + "}") .when() .post("https://reqres.in/api/users") .then() .extract().response(); System.out.println(response.prettyPrint());