0

I have the following JSON:

{
"X":20,
"Y":null
}

Now, for the key Y, i need to insert below json array.

{
"A":null,
"B":1,
"C":5000,
"D":0.25
}

I tried this but doesn't work:

String response1 = 
                    given()
                        .cookie(apiTestSessionID)
                        //.spec(requestSpecification)
                    .when()
                        //.get("/service/bill/Config")
                    .get("/service/bill/Config/0001")
                    .asString();

JsonPath jsonCstmrConfig = new JsonPath(response);

String response2 = given()
                .cookie(apiTestSessionID)
            .when()
            .get("/service/commoncache/card")
            .asString();
JsonPath jsonSoiRateCard = new JsonPath(response2);

Map<String,String> maps =  jsonCstmrConfig.getMap("data");
maps.put("X","Value");

Is there any way to do it with provided rest assured json library.

ButterSkotch
  • 75
  • 1
  • 1
  • 6

1 Answers1

0

Try below code, it uses Gson library

Gson gson = new Gson();

String response1 = given()
                .cookie(apiTestSessionID)
                .when()
                .get("/service/bill/Config/0001")
                .asString();

//Converting response string to JsonObject
JsonObject jsonObj = gson.fromJson (jsonStr, JsonElement.class).getAsJsonObject();

String response2 = given()
            .cookie(apiTestSessionID)
            .when()
            .get("/service/commoncache/card")
            .asString();

//Converting response string to JsonElement
JsonElement element = gson.fromJson (response2, JsonElement.class);

//Adding json data array to existing jsonObject
jsonObj.add("Y", element);
Purushotham
  • 3,770
  • 29
  • 41
  • Hi Uttam, I am facing few more issues, can you please help on this as well. http://stackoverflow.com/q/42691109/7640781 – ButterSkotch Mar 09 '17 at 13:47