Skip to content

Latest commit

 

History

History
73 lines (56 loc) · 2.24 KB

json-functions-utility.md

File metadata and controls

73 lines (56 loc) · 2.24 KB
title summary
JSON Utility Functions
Learn about JSON utility functions.

JSON Utility Functions

This document describes JSON utility functions.

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)

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.

Note:

Because TiDB has a different storage architecture from MySQL, this function always returns 0 for a valid JSON value, and it is implemented for compatibility with MySQL 8.0. Note that TiDB does not do in-place updates. For more information, see RocksDB space usage.

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

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