JSON_QUOTE() – How to Escape Characters in Strings used as JSON Values in MySQL

When working with JSON and MySQL, sometimes you might need to escape strings so that their quote characters don’t interfere with the interpretation of the JSON document. In such cases, you can use the JSON_QUOTE() function to escape potentially problematic strings.

JSON_QUOTE() is used to produce a valid JSON string literal that can be included in a JSON document.  For example, you might want an element in an array to have the text null as a string literal, rather than having an actual null value. This function can be used to ensure that the text is added as a string literal, rather than a null value.

To use it, simply call the function while passing in the string.

Continue reading

MIN() – Find the Minimum Value in a Column in MySQL

The MySQL MIN() function is an aggregate function that returns the minimum value from an expression.

Typically, the expression would be a range of values returned as separate rows in a column, and you can use this function to find the minimum value from the returned rows. If there are no matching rows, MIN() returns NULL.

For example, you can use this function to find out which city has the smallest population out of a list of cities.

Continue reading