Exploring the realm of JSON notation as a newcomer has presented me with an intriguing challenge. I find myself in a situation where I need to reformat the current database format to align with a new structure suitable for importing into a project timeline graph.
The initial JSON format retrieved from the database is as follows:
[
{
"name":"5-HP-N/A-N/A-F8",
"node":{
"name":"5",
"id":14
},
"timeline":{
"epc":null,
"m1":null,
"m2":null,
"m3":1554087600000,
"m4":1593572400000,
"m5":1625108400000,
"m6":1641006000000,
"m7":1656644400000
},
"fab":{
"name":"F8",
"id":1
}
},
However, the desired JSON format essential for graph display is structured as follows:
{
'start': new Date(value from epc or first non-null milestone),
'end': new Date(value from m1 or first non-null milestone), // end is optional
'content': 'label from start Date milestone',
'group' : ' value from name field above 5-HP'
'classname' : ' value from start Date milestone'
});
I am currently in the process of crafting a function that can effectively achieve this objective. While only epc, m1, or m2 may hold null values, it is imperative to inspect these conditions to determine event ranges' creation and termination points. What would be the most efficient approach to reformat this json data (preferably sourced from an external json sheet)?
Edit: Grateful for the assistance provided so far! It now appears clearer how the reformatting works. On reflection, my initial explanation was not as exhaustive. My actual requirement involves multiple class items per "group".
The ultimate goal is for these items to be displayed sequentially on a timeline graph 'group' line. Consequently, I am exploring ways to generate distinct objects for each array element detailed above.
In practice, the first object's start date would correspond to m3, while its end date would align with m4. Subsequently, the consecutive object would share the same group as the preceding one (5-HP...), initiating at m4 and concluding at m5...and so forth. This sequence persists until m7 (always an end date but never a start date) is reached.
This complexity introduces various conditions, making the looping process less straightforward.