如何将MySQL查询结果转换为JSON对象?

时间:2022-01-29 21:20:26

Goal is to migrate some crucial data from MySQL db to a NoSQL document based db. To make the process simpler, I assume it's best to first convert mysql query result to JSON object. Is this possible?

目标是将一些关键数据从MySQL数据库迁移到基于NoSQL文档的数据库。为了简化这个过程,我认为最好先将mysql查询结果转换为JSON对象。这可能吗?

1 个解决方案

#1


1  

Suppose your SQL query's result set rows contain 4 values each, you just need to give these fields names and create a dict to insert into your NoSQL databse.

假设您的SQL查询的结果集行每个包含4个值,您只需要提供这些字段名称并创建一个插入NoSQL数据库的字典。

fieldnames = ['field1', 'field2', 'field3', 'field4']
dict_row = dict(zip(fieldnames, row))

#1


1  

Suppose your SQL query's result set rows contain 4 values each, you just need to give these fields names and create a dict to insert into your NoSQL databse.

假设您的SQL查询的结果集行每个包含4个值,您只需要提供这些字段名称并创建一个插入NoSQL数据库的字典。

fieldnames = ['field1', 'field2', 'field3', 'field4']
dict_row = dict(zip(fieldnames, row))