I have a JSON file containing an array of User objects. Each User object contains a Goals array containing objects and within each Goal object is a Milestone array containing 1 to many milestone objects.
I was able to utilize JSON-Simple to parse them with ease and store the information in the form of Java objects, but I'm finding it challenging to re-write certain blocks in the JSON file or append to one of the arrays. The examples I found online are too simplistic and didn't account for this much nesting.
If I wanted to rewrite a Goal object in my JSON file or a particular Milestone in the array of milestones, how would I go about updating the file based on the attributes assigned in their corresponding Java object models? Is it possible to modify/append a particular block in the JSON text file within one of the arrays?
[
{
"username": "example",
"password": "pwd",
"Goals":[
{
"goalId": "G0001",
"goalName": "COEN 275 Midterm",
"startDate": "02/14/2017",
"endDate": "02/28/2017",
"numMilestones": 5,
"color": "#4286f4",
"hoursPerDay": 4,
"milestones":[
{
"milestoneName": "Chapter 1",
"Difficulty": "E",
"dueDate": "02/18/2018",
"completed": true
},
{ "milestoneName": "Chapter 2",
"Difficulty": "E",
"dueDate": "02/22/2018",
"completed": true
},
{ "milestoneName": "Chapter 3",
"Difficulty": "M",
"dueDate": "02/23/2018",
"completed": true
},
{ "milestoneName": "Chapter 4",
"Difficulty": "M",
"dueDate": "02/25/2018",
"completed": false
},
{ "milestoneName": "Chapter 5",
"Difficulty": "H",
"dueDate": "02/28/2018",
"completed": false
}
]
}
]
},
{
"username": "username",
"password": "pwd",
"Goals":[
{
"goalId": "G0001",
"goalName": "COEN 279 Midterm",
"startDate": "02/14/2017",
"endDate": "02/28/2017",
"numMilestones": 5,
"color": "#4286f4",
"hoursPerDay": 4,
"milestones":[
{
"milestoneName": "Chapter 5",
"Difficulty": "E",
"dueDate": "02/18/2018",
"completed": true
},
{ "milestoneName": "Chapter 6",
"Difficulty": "E",
"dueDate": "02/22/2018",
"completed": true
},
{ "milestoneName": "Chapter 7",
"Difficulty": "M",
"dueDate": "02/23/2018",
"completed": true
},
{ "milestoneName": "Chapter 11",
"Difficulty": "M",
"dueDate": "02/25/2018",
"completed": false
},
{ "milestoneName": "Chapter 12",
"Difficulty": "H",
"dueDate": "02/28/2018",
"completed": false
}
]
}
]
}
]