Answer the question
In order to leave comments, you need to log in
Similar to JSON_TABLE in MYSQL so keys are one of the columns?
In some scenarios, I need to build a table from a column with json data.
For example, here is an object: {"1": 2, "2": 4, "3": 1, "4": [2, 3, 6]}
. All keys are unique among themselves. There are no nested objects.
The easiest way is to build such a table through their native commands:
1 2
2 4
3 1
4 2
4 3
4 6
[{"key": 1, "value: 2}, {"key": 2, "value": 4}]
. Answer the question
In order to leave comments, you need to log in
Is it really necessary to work in a loop with each pair through JSON_KEY and JSON_EXTRACT, and only form table rows in this way?Since such a data structure is chosen in JSON, then using SQL is the only way.
[{"key": 1, "value: 2}, {"key": 2, "value": 4}]
12.17.6 JSON Table Functions
This section contains information about JSON functions that convert JSON data to tabular data. In MySQL 8.0.4 and later, one such function—JSON_TABLE()—is supported.
All keys are unique to each other
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question