-1

I am using Rest Assured for API testing, how do I send array objects in a POST? For a plain string I know I can do something like this

JSONObject json = new JSONObject();
json.put("firstname", "John"));
json.put("lastname", "James");
request.body(json.toJSONString());
request.post("/my/post/url/end/point");

How do I send an object like this using the JSONObject and Rest Assured?

{
    "price": "234",
    "phoneNumber": "09022334422",
    "owner": [{
        "digits": "1122334455",
        "myname": "Abisoye Haminat",
        "code": "058",
        "default": "true"
    }]
}
halfer
  • 19,824
  • 17
  • 99
  • 186
ken4ward
  • 2,246
  • 5
  • 49
  • 89

1 Answers1

-1

To send an array, you can use JSONArray:

JSONObject jsonObjectToPost = new JSONObject();

JSONArray array = new JSONArray();

JSONObject arrayItem = new JSONObject();

arrayItem.put("code","058");
arrayItem.put("default", "true");

array.put(arrayItem.toString());

jsonObjectToPost.put("owner", array.toString())
Heir Of Knowledge
  • 617
  • 1
  • 6
  • 13