0
String jsonString = " 
{
 "success": true,
 "total": 282,
 "timeTaken": 31,
 "responseCode": 200,
 "facet_count": {},
 "inferred": 
{
 "city": null,
 "locality": null,
 "cityList": null,
 "state": null
 }
}
";

Problem : To update "locality" value to "ABCD"

I know how to do using com.jayway, below is the code for that

Configuration configuration = Configuration.builder()
    .jsonProvider(new JacksonJsonNodeJsonProvider())
    .mappingProvider(new JacksonMappingProvider()).build();

DocumentContext json = com.jayway.jsonpath.JsonPath.using(configuration)
    .parse(jsonString);
System.out.println(json.set("inferred.locality", "ABCD").jsonString());

But not able to do using io.rest-assured version 3.0.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
user522170
  • 623
  • 1
  • 6
  • 21
  • 1
    Could you give some more context? REST Assured is really good at making and validating REST calls in automated tests. I use it for that a lot. I mean **a lot**. But I never have a desire to update JSON. So if we understand what you're really trying to do, maybe we can make a different recommendation. – Sander Verhagen Dec 02 '18 at 10:31
  • need to test same json with multiple data set, that's why need to update json with different values – user522170 Dec 02 '18 at 13:27

1 Answers1

0

You can try representing the json as POJO and then try to update the value. It is possible to manipulate string directly however, it is neither recommended nor advisable.

JavaMan
  • 465
  • 1
  • 6
  • 21