Output SQL query results in JSON format

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: sql查询结果输出json格式

| username: 像风一样的男子

To improve efficiency, please provide the following information. A clear problem description can help resolve the issue faster:
【TiDB Usage Environment】
Big data retrieval

【Overview】 Scenario + Problem Description
Big data uses JSON format data. How can I directly output the SQL execution results in JSON format?

| username: forever | Original post link

Is the volume large? Navicat directly supports exporting in JSON format.

| username: 像风一样的男子 | Original post link

I want to batch pull data daily in the code and directly convert it to JSON.

| username: forever | Original post link

Single row:

SELECT JSON_OBJECT('id', sbtest9.id,
                   'k', sbtest9.k,
                   'c', sbtest9.c,
                   'pad', sbtest9.pad) AS json
FROM sbtest9
LIMIT 10;

Multiple rows:

SELECT sbtest9.*,
       JSON_ARRAYAGG(JSON_OBJECT('id', sbtest9.id,
                                 'k', sbtest9.k,
                                 'c', sbtest9.c,
                                 'pad', sbtest9.pad)) AS JsonArray
FROM sbtest9
GROUP BY c;
| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.