Product SiteDocumentation Site

Chapter 16. Equality vs. Identity

As in most languages, one can distinguish between physical equality and logical equality.
Atomics can only be compared logically. Their physically identity is totally opaque to you.
Example 16.1. Logical comparison of two atomics.
1 eq 1
Results:
true

Example 16.2. Logical comparison of two atomics.
1 eq 2
Results:
false

Example 16.3. Logical comparison of two atomics.
"foo" eq "bar"
Results:
false

Example 16.4. Logical comparison of two atomics.
"foo" ne "bar"
Results:
true

Two objects or arrays can be tested for logical equality as well, using deep-equal(), which performs a recursive comparison.
Example 16.5. Logical comparison of two JSON items.
deep-equal({ "foo" : "bar" }, { "foo" : "bar" })
Results:
true

Example 16.6. Logical comparison of two JSON items.
deep-equal({ "foo" : "bar" }, { "bar" : "foo" })
Results:
false

The physical identity of objects and arrays is not exposed to the user in the core JSONiq language itself. Some library modules might be able to reveal it, though.