MariaDB JSON_EQUALS(): Compare JSON Objects
MariaDB JSON_EQUALS() compares two JSON objects and returns 1 when they are equal, 0 when they are not, or NULL if either argument is NULL. It is available from MariaDB 10.7. See the official MariaDB JSON_EQUALS reference.
MariaDB’s JSON data type is an alias for LONGTEXT, so ordinary equality compares text and can depend on document formatting. Use JSON_EQUALS() when you need a JSON-aware comparison that tolerates object key order and whitespace differences.
Syntax
JSON_EQUALS(json1, json2)
Examples
Object key order and insignificant whitespace do not affect this comparison. The official example also shows the JSON numbers 3 and 3.0 comparing equal:
SELECT JSON_EQUALS(
'{"a" :[1, 2, 3],"b":[4]}',
'{"b":[4],"a":[1, 2, 3.0]}'
);
1Different array values make the objects unequal:
SELECT JSON_EQUALS('{"a":[1, 2, 3]}', '{"a":[1, 2, 3.01]}');
0If either SQL argument is NULL, the result is NULL rather than 0:
SELECT JSON_EQUALS(NULL, '{"a": 1}') AS comparison_result;
+-------------------+
| comparison_result |
+-------------------+
| NULL |
+-------------------+This is SQL NULL input handling; it does not mean the JSON document contains the JSON literal null.
For a normalized JSON text representation, see JSON_NORMALIZE().