Purpose
JSON_STORAGE_SIZE() returns the number of binary bytes used to store a JSON document. When the argument is a JSON column, this function is used to store a JSON document. Partial updates of the JSON document do not change the returned value of this function.
Syntax
JSON_STORAGE_SIZE(json_val)
Description
The value of json_val must be a valid JSON document or can be parsed into a string. When the value of json_val is a string, this function parses the string into a JSON document, converts it into binary bytes, and returns the number of binary bytes in the storage space.
When the value of json_val is not NULL and cannot be parsed into a JSON document, an error is returned.
If the argument is NULL, NULL is returned.
Examples
obclient> CREATE TABLE jtbl (jcol JSON);
Query OK, 0 rows affected
obclient> INSERT INTO jtbl VALUES ('{"a": 1000, "b": "wxyz", "c": "[1, 3, 5, 7]"}');
Query OK, 1 row affected
obclient> SELECT jcol,JSON_STORAGE_SIZE(jcol) AS Size FROM jtbl;
+-----------------------------------------------+------+
| jcol | Size |
+-----------------------------------------------+------+
| {"a": 1000, "b": "wxyz", "c": "[1, 3, 5, 7]"} | 41 |
+-----------------------------------------------+------+
1 row in set
obclient> SET @jn = '[100, "sakila", [1, 3, 5], 425.05]';
Query OK, 0 rows affected
obclient> SELECT @jn, JSON_STORAGE_SIZE(@jn) AS Size;
+------------------------------------+------+
| @jn | Size |
+------------------------------------+------+
| [100, "sakila", [1, 3, 5], 425.05] | 38 |
+------------------------------------+------+
1 row in set
obclient> SET @jn = JSON_SET(@jn, '$[1]', "json");
Query OK, 0 rows affected
obclient> SELECT @jn, JSON_STORAGE_SIZE(@jn) AS Size;
+----------------------------------+------+
| @jn | Size |
+----------------------------------+------+
| [100, "json", [1, 3, 5], 425.05] | 36 |
+----------------------------------+------+
1 row in set