I have an object that has a coefficients property that's buried six levels deep in the outer object.
I need to pass the entire object to a PHP file on our backend to process it for entries into our MySQL database.
I don't seem to be able to get the entire object by using deep cloning (using LoDash), or spread operator {...}
or JSON.parse(JSON.stringify(obj));
.
In every case I end up with just a blank set of square brackets where the data I'm interested in lives.
What I end up with is this (see the last blank entry for coefficients):
{
"dostuff": "saveCalibrationStart",
"debug": true,
"configurationID": 0,
"computername": "REDACTED",
"username": "REDACTED",
"notes": "none",
"softwarename": "CalRun",
"softwareversion": "V12.0.0 beta > 1.13",
"systemid": "42",
"devices": [
{
"modelNumberID": "12",
"serialNumber": "09998",
"position": 1
}
],
"references": [
{
"modelNumberID": "12",
"calibrationDeviceTypeID": 11,
"serialNumber": "09999",
"measurands": [
{
"measurementTypeID": "13",
"measurand": "Phenanthrene",
"calibrationDate": "2019-01-01",
"coefficients": []
}
]
}
]
}
This guy's page on the spread operator seemed promising, but I'm getting the same thing: https://flaviocopes.com/javascript-spread-operator/
Further experimentation indicates that no matter what I do, I end up with the empty array for the coefficients, when they should looks like this:
If I save the object as a global variable (Chrome), I am able to access, change and manipulate the elements of the coefficients like this:
temp1.references[0].measurands[0].coefficients
This seems like a simple task, grab the object, turn it into JSON & hand it off to the backend for processing, but it's been vexing me for a couple of days.