Description
This function returns the number of binary bytes required to store a JSON document. When the parameter is a JSON column, it specifies the column used to store the JSON document. Partial updates to the JSON data do not change the return value of this function.
Syntax
JSON_STORAGE_SIZE(json_val)
Description
The json_val parameter must be a valid JSON document or something that can be parsed into a string. When json_val is a string, the function parses it into JSON, converts it to binary, and returns the number of binary bytes occupied by the storage space.
An error is reported when json_val is not NULL and cannot be successfully parsed into a JSON document.
If the parameter 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