Hi everyone,
I have a project that require to insert JSON data into MySQL database using plain javascript.
Let’s assume I have the following data and I need it to be decoded and inserted to mysql database.
{ "class": "go.GraphLinksModel",
"nodeDataArray": [
{"key":1, "text":"Alpha Co Ltd", "colour":"white", "category":"Loading", },
{"key":2,"text":"Sales", "level":"division", "colour":"skyblue"},
{"key":3,"text":"Operations", "level":"division", "colour":"limegreen"},
{"key":4,"text":"Onboarding", "level":"process", "colour":"skyblue"},
{"key":5,"text":"Sales Reps", "level":"process", "colour":"skyblue"},
{"key":6,"text":"Operations", "level":"process", "colour":"limegreen"},
{"key":7,"text":"Oracle", "level":"application", "colour":"grey"},
{"key":8,"text":"MS Access", "level":"application", "colour":"grey"},
{"key":9,"text":"MS Access", "level":"application", "colour":"grey"},
{"key":10,"text":"SAP", "level":"application", "colour":"grey"},
{"key":11,"text":"Leads", "level":"dataset", "colour":"lightgrey"},
{"key":12,"text":"Referrals", "level":"dataset", "colour":"lightgrey"},
{"key":13,"text":"Sales Reps", "level":"dataset", "colour":"lightgrey"},
{"key":14,"text":"Orders", "level":"dataset", "colour":"lightgrey"},
{"key":15,"text":"Customer ID", "level":"dataelement", "colour":"white", "category":"End"},
{"key":16,"text":"Customer name", "level":"dataelement", "colour":"white", "category":"End"},
Confidential - Rockit Solutions Limited November 2018
{"key":17,"text":"SalesRep ID", "level":"dataelement", "colour":"white", "category":"End"},
{"key":18,"text":"SalesRep name", "level":"dataelement", "colour":"white", "category":"End"},
{"key":19,"text":"SalesRep name", "level":"dataelement", "colour":"white", "category":"End"},
{"key":20,"text":"Order ID", "level":"dataelement", "colour":"white", "category":"End"},
{"key":21,"text":"Customer ID", "level":"dataelement", "colour":"white", "category":"End"},
{"key":22,"text":"SalesRep ID", "level":"dataelement", "colour":"white", "category":"End"}
],
"linkDataArray": [
{"from":1, "to":2},
{"from":1, "to":3},
{"from":2, "to":4},
{"from":2, "to":5},
{"from":3, "to":6},
{"from":4, "to":7},
{"from":4, "to":8},
{"from":5, "to":9},
{"from":6, "to":10},
{"from":7, "to":11},
{"from":8, "to":12},
{"from":9, "to":13},
Confidential - Rockit Solutions Limited November 2018
{"from":10, "to":14},
{"from":11, "to":15},
{"from":11, "to":16},
{"from":12, "to":17},
{"from":12, "to":18},
{"from":13, "to":19},
{"from":14, "to":20},
{"from":14, "to":21},
{"from":14, "to":22}
]
}
It requires the following 5 fields:
-
Parent ID. Automatically generated unique ID.
-
Child Type. The type is one of (Process, Application, Dataset or DataElement)
-
Child Node. The node label text.
-
Child ID. Automatically generated unique ID.
-
GroupColour. Only applies to Nodes of type=Process.
When the script is run, parse the JSON data to identify unique IDs for every node.
Each of the four node types {Process, Application, Dataset and DataElement} should be given a unique ID prefixed by PRO, APP DSE, DEL respectively. So if there are 3 processes they would have IDs; PRO1,PRO2,PRO3. These must be continuous ID numbers and there must not be any gaps in between eg PRO1,PRO2,PRO4.
For every node identify the child name (ie the text label), type (ie Process, Application, Dataset, DataElement), child ID, parent ID and colour (eg sky-blue) if applicable.
Please, if anyone can give me some advice about haw can I achieve this.
Thank you in advance.