Forum Discussion
the “in” operator return true if there a property with null value. and if you further check for sub-child it errors out.
example 1:-
$:{
child:null
}
example 2:-
$: {
child: {
child1: “some value”
}
$.hasOwnProperty() helps in filtering this type of use cause while “in” operator return true for example-1, (‘child’ in $) and will generate an error “Requires an Array or Object in-the-Right-hand-side” for example-1 if you try this expression: (‘child’ in $) && (‘child1’ in $.child) but it will work for example 2.
get() method works for both the case in order to filter out property based on null try this: ($.get(“child”) != null) && ($.child.get(“child1”) != null). Is “in” operator (shorthand for get()) bugged ?
Get method:
Sorry for bad formatting.
Your expression should be
'child' in $ && 'child1' in $child
The above will return true is child1 exists in child. Its not $.child
Hope that makes sense.
- jaybodra9 years agoNew Contributor III
isn’t this expression $.child compliant with java script?
- tstack9 years agoFormer Employee
Yes, “$.child”, “$child”, and “$[‘child’]” all mean the same thing in the expression language, which is to get the value of the property named “child”. The “$” symbol refers to the input document, so “$.child” and “$[‘child’]” mean lookup “child” in the document. The “$child” syntax (i.e. no dot) is a shorthand that is accepted.