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.