hasOwnProperty() and fields containing special characters

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

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.

Getting a little creative, I got this to work for me:

JSON.stringify($Errors).contains(’"$.Field_1":’)

$Errors.hasOwnProperty("[’$.field1’]") gives the correct answer.

Thanks & Regards,
Naveen

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.