如何在mysql中查询JSON地图?

How to query a JSON map in mysql?

我想查询一个JSONmysql字段如下:

json:

{
    "key1": [
        {
            "firstname": "jane"
        },
        {
            "firstname": "john"
        }
    ]
}

我想搜索“key1”,并提取 [0].firstname 字段,在本例中为 jane

但是我怎样才能用 JSON_EXTRACT() 或类似的方法实现这个呢?

mysql> set @j = '...your json example...';

mysql> select json_unquote(json_extract(@j, '$.key1[0].firstname')) as fn;
+------+
| fn   |
+------+
| jane |
+------+