below is json string :
{
"Data1": "",
"Data2": {
"id": 1234
},
"Data3": [
{
"id": "id2",
"price": [
{
"id": "id3"
}
],
"account": {
"id": "%s"
},
"product": {
"extension": {
"sub": "R"
}
},
"reason": [
{
"extension": {}
}
],
"produracteristic": [
{
"name": "gt",
"value": "none"
}
],
"extension": {
}
}
],
"Data4":[
....
}
}
I want to add data under json payload.Data3.extension want to add date:28-08-2023, so it will be ,
"extension": {
date:28-08-2023
}
I have tried using java but that was only working for add element in json array. but in my case I am not adding in array . I am adding it to an object under array. Please help me on this
JsonPath pathToArray = JsonPath.compile("$.data3.extension");
documentContext.add(pathToArray, Collections.singletonMap("date", "28-08-2023"));
I have use the dependency named Fastjson, and found it easy to implementd it.
Follow is my code.
The output is:
If you want to use this ,you can add this in your maven files.