โ06-15-2017 11:26 AM
Given the object:
{
"Errors" : {
"$.Field_1" : "Too many characters.",
"Field_2" : "Too few characters."
}
}
The following expressions yield different results:
$Errors.hasOwnProperty('$.Field_1') ==> false
$Errors.hasOwnProperty('Field_2') ==> true
We tried all manner of escaping the โ$.Field_1โ to no avail, before finding a different path that does not require the โhasOwnPropertyโ call.
But I am still curious if this is an issue of not escaping the argument correctly, or a bug in the hasOwnProperty() implementation?
Thanks,
TK
โ06-15-2017 11:34 AM
Sorry, looks like an ancient bug in hasOwnProperty(). Itโs treating its argument as a JSON-Path instead of a plain property name. Thatโs wrong. Not sure how to workaround it yet.
โ06-15-2017 04:13 PM
Getting a little creative, I got this to work for me:
JSON.stringify($Errors).contains(โโ$.Field_1โ:โ)
โ06-15-2017 05:46 PM
$Errors.hasOwnProperty(โ[โ$.field1โ]โ) gives the correct answer.
Thanks & Regards,
Naveen
โ06-15-2017 05:48 PM
The bug will eventually be fixed, so I would prefer people not try to workaround it like this since it will begin failing after the fix.