MySQL includes some inbuilt functions that can be used to create JSON values, such as JSON arrays, JSON objects, or a quoted string literal.
Here are seven functions that allow us to create JSON values in MySQL.
Continue readingMySQL includes some inbuilt functions that can be used to create JSON values, such as JSON arrays, JSON objects, or a quoted string literal.
Here are seven functions that allow us to create JSON values in MySQL.
Continue readingBelow is a list of the JSON functions and operators available in MySQL.
Continue readingIn MySQL, we have several options when it comes to removing the quotes from a JSON value.
For example, normally if we return a string value from a JSON document, we would get that value along with its quotes. But sometimes we might not want the quotes. Below are three methods we can use to unquote a JSON value in MySQL.
Continue readingIn MySQL, the JSON_SCHEMA_VALIDATION_REPORT()
function validates a JSON document against a JSON schema and returns a report of the outcome of that validation. The report is returned as a JSON document.
If the document is valid, only one field is returned: "valid" : true
. If the document is not valid, a more extensive report is provided.
In MySQL, the JSON_SCHEMA_VALID()
function validates a JSON document against a JSON schema. It returns true (1
) if the document is valid, and false (0
) if it is not.
In MySQL, we can use the ->>
operator to extract a value from a JSON document, and unquote that value.
We provide the column that contains the JSON document to the left of the operator, and the path to the value that we want to extract to the right.
The ->>
operator is equivalent to JSON_UNQUOTE(JSON_EXTRACT())
, and it provides the same results.
In MySQL, we can use the ->
operator to extract data from a JSON document.
We provide the column that contains the JSON document to the left of the operator, and the path to the value that we want to extract to the right.
The ->
operator is an alias for the two-argument form of the JSON_EXTRACT()
function.
In MySQL, the MEMBER OF()
operator tests whether or not a value is a member of a given JSON array.
It returns true (1
) if the array contains the value, and false (0
) if it doesn’t.
The MEMBER OF()
operator was added in MySQL 8.0.17.
In MySQL, JSON_OVERLAPS()
is a function that tests whether or not two JSON documents have any key-value pairs or array elements in common.
The function returns true (1
) if the documents have any key-value pairs or array elements in common, and false (0
) if they don’t.
The JSON_OVERLAPS()
function was added in MySQL 8.0.17.
In MySQL, JSON_MERGE()
is a deprecated function that merges two or more JSON documents and returns the result.
It was deprecated in MySQL 8.0.3 and is subject to removal in a future release.
Fortunately, the JSON_MERGE_PRESERVE()
function was added in MySQL 8.0.3 as a synonym for JSON_MERGE()
, and it therefore does the same thing that JSON_MERGE()
does/did.
Therefore, instead of using JSON_MERGE()
, use JSON_MERGE_PRESERVE()
instead.
Alternatively, you can use JSON_MERGE_PATCH()
, which performs an RFC 7396 compliant merge of two or more JSON documents, without preserving members having duplicate keys.