Example: 

{"a": 1, "b": 2} = {"b": 2, "a": 1} 

The order of two objects that are not equal is unspecified but deterministic. 

• STRING 

Strings are ordered lexically on the first N  bytes of the utf8mb4  representation of the two strings being compared, where N  is the length of the shorter string. If the first N  bytes of the two strings are identical, the shorter string is considered smaller than the longer string. 

Example: 

"a" < "ab" < "b" < "bc" 

This ordering is equivalent to the ordering of SQL strings with collation utf8mb4_bin . Because utf8mb4_bin  is a binary collation, comparison of JSON values is case-sensitive: 

"A" < "a" 

• INTEGER , DOUBLE 

JSON values can contain exact-value numbers and approximate-value numbers. For a general discussion of these types of numbers, see Section 9.1.2, “Numeric Literals” . 

The rules for comparing native MySQL numeric types are discussed in Section 12.3, “Type Conversion in Expression Evaluation” , but the rules for comparing numbers within JSON values differ somewhat: 

•In a comparison between two columns that use the native MySQL INT  and DOUBLE  numeric types, respectively, it is known that all comparisons involve an integer and a double, so the integer is converted to double for all rows. That is, exact-value numbers are converted to approximate-value numbers. 

•On the other hand, if the query compares two JSON columns containing numbers, it cannot be known in advance whether numbers are integer or double. To provide the most consistent behavior across all rows, MySQL converts approximate-value numbers to exact-value numbers. The resulting ordering is consistent and does not lose precision for the exact-value numbers. For example, given the scalars 9223372036854775805, 9223372036854775806, 9223372036854775807 and 9.223372036854776e18, the order is such as this: 

9223372036854775805 < 9223372036854775806 < 9223372036854775807 < 9.223372036854776e18 = 9223372036854776000 < 9223372036854776001 

Were JSON comparisons to use the non-JSON numeric comparison rules, inconsistent ordering could occur. The usual MySQL comparison rules for numbers yield these orderings: 

•Integer comparison: 

9223372036854775805 < 9223372036854775806 < 9223372036854775807 

(not defined for 9.223372036854776e18) 

•Double comparison: 

9223372036854775805 = 9223372036854775806 = 9223372036854775807 = 9.223372036854776e18 

For comparison of any JSON value to SQL NULL , the result is UNKNOWN . 

