I have to work with the following pre-defined JSON request. This JSON is stored in a local file. I would like to update the values of a couple of elements ("level-4b-1" and "level-4b-3" > "StartDate") in the JSON and submit the request.
{
"level-1": {
"level-2": {
"level-3": {
"level-4a": [
"value-4a"
],
"level-4b": [
{
"level-4b-1": "value-4b-1",
"level-4b-2": "value-4b-2",
"level-4b-3": {
"StartDate": "2017-11-13T00:00:00"
}
}
]
},
...
I have the following code but I am not sure how to go deeper in a single line of code and then update the value.
JSONParser parser = new JSONParser();
Object requestFileObj = parser.parse(new FileReader(context.getRealPath(localJsonFile)));
JSONObject requestJsonObject = (JSONObject) requestFileObj;
if (requestJsonObject instanceof JSONObject) {
JSONObject level1 = (JSONObject)chartRequestJsonObject.get("level-1");