MariaDB JSON_EXISTS() Explained

In MariaDB, JSON_EXISTS() is a built-in function that allows you to check whether a value exists at a specified path in the JSON document.

It accepts the JSON document as an argument, and returns 1 if the path is found, and 0 if it’s not.

The MariaDB documentation states that the function “determines whether a specified JSON value exists in the given data”. However, the function doesn’t actually appear to check for a given value. It’s probably more accurate to say that it determines whether a specified path exists, or that a value exists at the specified path.

For checking that the actual value exists, you can use the JSON_CONTAINS() function.

Continue reading

MariaDB JSON_MERGE_PRESERVE() Explained

In MariaDB, JSON_MERGE_PRESERVE() is a built-in function that merges two or more JSON documents and returns the result.

JSON_MERGE_PRESERVE() is a synonym for JSON_MERGE(), which has been deprecated. To avoid future issues, you should use the JSON_MERGE_PATCH() function instead. The JSON_MERGE_PATCH() function is an RFC 7396-compliant replacement for JSON_MERGE().

Continue reading

MariaDB JSON_COMPACT() Explained

In MariaDB, JSON_COMPACT() is a built-in function that removes all unnecessary spaces from a JSON document, so that it’s as short and compact as possible, and returns the result.

This can be handy for when you need to store JSON data in a database column, and you don’t want the JSON documents to use up any more space than is necessary.

For the opposite effect (i.e. to prettify a JSON document by adding indents and spreading it over multiple lines), use the JSON_DETAILED() function.

Continue reading