I have encountered situations where the JSON data I receive from services and database calls, created by a different team, contains invalid data combinations that lead to unintended errors downstream.
For example, in the case below, if the "rowContent" field is set to "1", its corresponding "row" should be a populated JavaScript object. While "rowContent1" and "row1", as well as "rowContent2" and "row2" are correct pairings, "rowContent3" and "row3" do not match up properly.
I understand that the structure of this JSON is not ideal. It may seem a bit unconventional but this closely resembles what I am dealing with in production. Unfortunately, I have limited control over it.
Are there any data-driven methods to outline JSON data relationships like this in a way that can validate them before attempting to utilize non-existing data in "row3"?
Alternatively, what steps would you suggest I take in this scenario?
Thank you,
-Larry
{ "table" : [
{
"aRowContent" : {
"rowContent1" : "1",
"rowContent2" : "0",
"rowContent3" : "1",
},
"row1" : {
"myRowValue" : "red"
},
"row2" : null,
"row3" : null
}
]
}