I have an object being returned that I don't know the structure of beforehand. The only thing I know is what values should be in the object. My goal isn't to check whether or not the returned object specifically matches another, but to check whether specific nested key-value pairs exist in the returned object.
The following is a random object that I could expect to be returned and the values that I want to check for. Is there anything out there already written that performs this type of check? Sorry for the lack of code, but I'm not sure where to really begin with this. I thought about maybe flattening the objects and doing a check, but due to unknown array lengths that idea didn't pan out.
// ob1 is the random object being returned. This will not be the same every time.
ob1 = {
key_a: "val_a1",
key_b: [
"val_b1",
"val_b2",
"val_b3"
]
}
ob2a = {
key_b: [
"val_b2"
]
}
ob2b = {
key_a: "val_a1",
key_b: [
"val_b3"
]
}
ob2c = {
key_b: [
"val_b2"
"val_b3"
]
}
ob2d = {
key_b: [
"val_b1",
"val_doesnt exist"
]
}
ob2e = {
key_b: "val_b1"
}
checkExists(ob1,ob2a) // true
checkExists(ob1,ob2b) // true
checkExists(ob1,ob2c) // true
checkExists(ob1,ob2d) // false
checkExists(ob1,ob2e) // false