将 MySql table 导出到 JSON 对象

Exporting MySql table into JSON Object

如何将我的 mysql table 结果转换为数据库级别的 json 对象

例如,

SELECT json_array(
         group_concat(json_object( name, email))
FROM ....

它将产生结果

[ 
   { 
     "name": "something",
     "email": "someone@somewhere.net"
    }, 
   { 
     "name": "someone",
     "email": "something@someplace.com"
    }

]

但我需要的是我需要给出我自己的查询,其中可能包含函数、子查询等

就像在 postgres 中一样 select row_to_json(select name,email,getcode(branch) from .....) 然后我将得到整个结果作为 json object

在mysql中有没有可能这样做?

select jsonArray(select name,email,getcode(branch) from .....) 

我只在 Mysql 8 和 5.7 官方文档中发现它支持转换为 JSON 类型。它包括 MySQL 8 和 5.7 中的 JSON_ARRAY 函数,以及 MySQL 8 中的 JSON_ARRAYAGG 函数。请参阅完整的 JSON 函数参考 here.

这意味着不存在简单的 mysql 解决问题的内置方法。

幸运的是,我们的同事也发起了类似的讨论here。也许你可以在那里找到你的解决方案。

对于寻找明确定义的属性 JSON 转换,解决方案是