I'm trying to add one more index value to the path:
$.data.library.category[2].book
using jayway jsonpath
in following Json,
"data":{
"library":{
"class":"CRED",
"category":[{
"book":"java 2.0"
},
{
"book":"java 3.0"
}]
}
but i'm not getting updated response in result json.
My java code:
Configuration conf = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL).addOptions(Option.SUPPRESS_EXCEPTIONS);
DocumentContext documentContext = JsonPath.using(conf).parse(sampleJson);
documentContext.set(JsonPath.compile("$.data.library.category[2].book"), "java 3.0");
I have checked also with documentContext.add
. Nothing works out. Since the array has 0 and 1 index, i can update the value there by JsonPath. But it dont have 2nd index, so not updating. But I need to insert new index in the last of given json as per jsonpath.