I'm looking for a simple workaround to import an existing nested JSON data into several MySQL tables. JSON does not have bidirectional relations so they should be generated automatically, I think.
Here is a data sample:
[
{
"targetgroup": "Staff",
"plan": "this field just exists and should be ignored in database",
"budgetlevel": "Government",
"spots": 5,
"edutype": "Bachelor",
"qualilevel": "Specialist",
"speciality": "Mathematician",
"qualification": "Finished",
"faculty": "Applied mathematics",
"institute": "this field is sometimes empty in input data",
"eduform": "Full-time",
"profiles": [
"Jr. Arithmetic manager"
],
"entrancetests": [
{
"subject": "math",
"typeoftest": "GOV",
"minscore": "37",
"ratingtype": "out of 100"
},
{
"subject": "language",
"typeoftest": "GOV",
"minscore": "27",
"ratingtype": "out of 100"
},
{
"subject": "physics",
"typeoftest": "GOV",
"minscore": "40",
"ratingtype": "out of 100"
}
]
},
{
"targetgroup": "Educational workers",
"plan": "fridge",
"budgetlevel": "Legacy",
"spots": 26,
"edutype": "Bachelor",
"qualilevel": "Master",
"speciality": "Data analysis",
"qualification": "Finished",
"faculty": "Machine learning mathematics",
"institute": "",
"eduform": "Full-time",
"profiles": [
"Head counting manager"
],
"entrancetests": [
{
"subject": "Discrete mathematics",
"typeoftest": "GOV",
"minscore": "32",
"ratingtype": "Out of 100"
},
{
"subject": "Algorythm theory",
"typeoftest": "GOV",
"minscore": "51",
"ratingtype": "Out of 100"
},
{
"subject": "Advanced exception catching",
"typeoftest": "GOV",
"minscore": "56",
"ratingtype": "Out of 100"
}
]
}
]
Database structure:
table "dep:"
id(auto increment) | targetgroup | budgetlevel | spots | edutype ... etc, same as JSON field names
table "profiles"
id (relative to corresponding parent block) | name
table "entrancetests":
id (relative to corresponding parent block) | subject | typeoftest | minscore | ratingtype
I have a general idea about how to import non-nested JSON but I have a hard time figuring out how do I add relations, how do I define parent block inside the loop?