mysql从数组中提取json元素

时间:2018-03-02 06:12:56

标签: mysql json

我需要通过索引提取JSON元素,例如

SELECT JSON_EXTRACT('[{"featureId":"a","read":1,"write":1,"delete":1},{"featureId":"2","read":1,"write":0,"delete":1}]', '$[0].*');

但它只是提取我​​想要提取的部分的值如下:

{
    "featureId": "a",
    "read": 1,
    "write": 1,
    "delete": 1
}

1 个答案:

答案 0 :(得分:0)

尝试:

SELECT JSON_EXTRACT('
  [
    {"featureId":"a","read":1,"write":1,"delete":1},
    {"featureId":"2","read":1,"write":0,"delete":1}
  ]
', '$[0]');

请参阅db-fiddle