I am using MySQL 5.7+ with the native JSON data type.
Sample data:
set @jsn_string='{\"body\": {\"items\": \"[{\\"count\\":530,\\"id\\":5},{\\"count\\":1,\\"id\\":519},{\\"count\\":209,\\"id\\":522},{\\"count\\":0,\\"id\\":3004}]\"}}';
Questions:
i want to retrieve iterated key, value.
The following result has the position of the data
select json_extract(replace(replace(replace(trim(@jsn_string), '\"[', '['), ']\"', ']'), '\\"', '\"'),'$.body.items[0].id') as id,
json_extract(replace(replace(replace(trim(@jsn_string), '\"[', '['), ']\"', ']'), '\\"', '\"'),'$.body.items[0].count') as count;
result is id count 5 530
but i want all of array, such as below
id[0] count[0],
id[1] count[1],
id[n] count[n]