CREATE TABLE t (j LONGTEXT);
INSERT INTO t (j) VALUES ('{"a":"1"}');
INSERT INTO t (j) VALUES ('{"b":"2"}');
INSERT INTO t (j) VALUES ('{"c":"0", "d":"0"}');
INSERT INTO t (j) VALUES ('{"c":"1", "d":"1"}');
SELECT JSON_KEYS(j) FROM t;
+--------------+
| JSON_KEYS(j) |
+--------------+
| ["a"] |
| ["b"] |
| ["c", "d"] |
| ["c", "d"] |
+--------------+
I am looking for a list of every keys in the whole table? Is that possible?
Such as
+----------------------+
| ["a", "b", "c", "d"] |
+----------------------+
r even better.
+-----+
| "a" |
| "b" |
| "c" |
| "d" |
+-----+
3
Answers
Depending on what you want, one of:
or
or
This can be done using
JSON_TABLE
as follows :Demo here
You can use
JSON_TABLE()
along withJSON_KEYS()
for version 10.6+ :Demo