JSON Utility Functions

This document describes JSON utility functions.

JSON_PRETTY()

The JSON_PRETTY(json_doc) function does pretty formatting of a JSON document.

SELECT JSON_PRETTY('{"person":{"name":{"first":"John","last":"Doe"},"age":23}}')\G
*************************** 1. row *************************** JSON_PRETTY('{"person":{"name":{"first":"John","last":"Doe"},"age":23}}'): { "person": { "age": 23, "name": { "first": "John", "last": "Doe" } } } 1 row in set (0.00 sec)

JSON_STORAGE_FREE()

The JSON_STORAGE_FREE(json_doc) function returns how much storage space is freed in the binary representation of the JSON value after it is updated in place.

SELECT JSON_STORAGE_FREE('{}');
+-------------------------+ | JSON_STORAGE_FREE('{}') | +-------------------------+ | 0 | +-------------------------+ 1 row in set (0.00 sec)

JSON_STORAGE_SIZE()

The JSON_STORAGE_SIZE(json_doc) function returns an approximate size of bytes required to store the JSON value. Because the size does not account for TiKV using compression, the output of this function is not strictly compatible with MySQL.

SELECT JSON_STORAGE_SIZE('{}');
+-------------------------+ | JSON_STORAGE_SIZE('{}') | +-------------------------+ | 9 | +-------------------------+ 1 row in set (0.00 sec)

See also

Was this page helpful?