Post data using rest assured. Method 2

Second way to post to rest is to create a JsonObject and put key value pairs in it. Then create a JsonArray and put that array as key value pair in JsonObject.

RestAssured.baseURI = "http://localhost";
RestAssured.port = 8080;
RestAssured.basePath = "/student";
        
JSONObject jsonObject  =  new JSONObject();
jsonObject.put("firstName","Hs");
jsonObject.put("lastName","D");
jsonObject.put("email","hs@example.com");
jsonObject.put("programme","CS");
        
JSONArray jsonArray = new JSONArray();
        
jsonArray.add("Math");
jsonArray.add("Java");
jsonArray.add("Python");
        
jsonObject.put("courses",jsonArray);
        
Response resp =  given().contentType(ContentType.JSON).log().body().body(jsonObject.toString()).post(;
      
resp.prettyPrint();