When formatting the output of query as JSON a closing curly brace is missing in the data section.

**Does it reproduce on recent release?**
Reproducible in 21.1.2

**How to reproduce**
```
ClickHouse client version 21.1.2.15 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.1.2 revision 54443.
```

I used the Github dataset, created the table and importet data according to (https://github-sql.github.io/explorer/#download-the-dataset)

The query (from (https://github-sql.github.io/explorer/#how-has-the-list-of-top-repositories-changed-over-the-years), added `FORMAT JSON`)

```
SELECT
    repo AS name,
    groupArrayInsertAt(toUInt32(c), toUInt64(dateDiff('month', toDate('2015-01-01'), month))) AS data
FROM
(
    SELECT
        lower(repo_name) AS repo,
        toStartOfMonth(created_at) AS month,
        count() AS c
    FROM github_events
    WHERE (event_type = 'WatchEvent') AND (toYear(created_at) >= 2015) AND (repo IN
    (
        SELECT lower(repo_name) AS repo
        FROM github_events
        WHERE (event_type = 'WatchEvent') AND (toYear(created_at) >= 2015)
        GROUP BY repo
        ORDER BY count() DESC
        LIMIT 10
    ))
    GROUP BY
        repo,
        month
)
GROUP BY repo
ORDER BY repo ASC
FORMAT JSON
```
returns
```
{
        "meta":
        [
                {
                        "name": "name",
                        "type": "LowCardinality(String)"
                },
                {
                        "name": "data",
                        "type": "Array(UInt32)"
                }
        ],

        "data":
        [
                {
                        "name": "996icu\/996.icu",
                        "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,182752,143840,7373,2344,1992,1526,1128,1021,1356,1493,874,559,856,885,1044,721,1018,1147,1157,783,784,197]
                },
                {
                        "name": "facebook\/react",
                        "data": [1804,2785,2404,2059,1657,1493,1681,1578,1791,1944,1881,1900,2028,1688,2425,2206,1796,1820,2166,2076,2802,2522,2383,2134,3016,2833,2995,2658,2768,2717,2979,2677,3115,3271,2904,2591,3169,2429,3380,2744,2684,9092,2845,2711,2644,2376,2545,2198,2670,2618,3261,2917,2760,2144,2325,2132,2082,2130,2058,1943,1834,1821,2033,2282,2456,2122,2547,2290,2133,2131,2097,376]
                },
                {
                        "name": "freecodecamp\/freecodecamp",
                        "data": [59,37,36,29,59,1196,10700,6194,3748,7826,11147,12775,17333,19204,16711,16233,18109,20430,10388,10157,11378,13257,14436,14567,15461,14096,14661,15004,16828,13811,1195,1203,922,1194,1041,943,1034,928,1212,952,854,1062,1583,1271,1036,2424,1044,982,1155,1129,2922,3314,1609,1081,1234,1055,1186,1249,1787,1234,1136,1091,1194,1556,1621,1303,1607,1506,1486,1669,1243,289]
                },
                {
                        "name": "getify\/you-dont-know-js",
                        "data": [826,2772,877,1218,987,1492,998,1123,1975,1420,1188,1528,1446,1375,1466,1528,1585,4382,2625,2233,2383,1802,2086,2064,3389,2464,3178,2969,2637,2519,2409,2223,1820,1646,1844,1804,2292,1921,2183,2360,1745,1667,1600,1861,1713,1621,1620,1431,1818,1649,2216,2119,1838,1853,1969,1960,1471,1891,1945,1918,2178,2673,1518,1445,2104,1874,1556,1591,1467,1634,1195,543]
                },
                {
                        "name": "jwasham\/coding-interview-university",
                        "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,54,3043,4460,1518,983,1125,1071,1036,1202,1043,5860,1835,1609,1532,2303,2344,1384,1085,1166,1334,1275,1014,1374,1103,1057,1457,1271,1412,1195,4281,5654,2275,1970,2430,1451,1988,3288,4510,6989,8344,4294,5546,6347,3860,5833,2856,736]
                },
                {
                        "name": "kamranahmedse\/developer-roadmap",
                        "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13979,5944,3246,1566,1075,1191,1114,961,777,644,9617,4919,2266,3231,1710,1684,2149,2038,1614,2802,1616,1632,6700,4052,2847,3153,2092,1812,2038,1879,1529,1379,1724,1637,2546,2096,2259,8192,4466,3037,5168,4938,5821,6674,5038,709]
                },
                {
                        "name": "microsoft\/vscode",
                        "data": [0,0,0,0,0,0,0,0,0,0,8199,1290,1047,892,1094,1959,1106,921,871,866,1042,1122,1201,1163,1767,1951,2028,1843,1704,1483,1620,1772,1779,2692,2852,2013,2179,1965,2175,1864,2312,3130,1994,2251,2300,2508,1855,1678,1875,1971,2918,2356,2973,1990,1918,1886,1856,1771,2712,2117,1700,1585,1898,2139,2276,1955,2290,1978,1800,1864,1791,331]
                },
                {
                        "name": "sindresorhus\/awesome",
                        "data": [423,263,297,360,6808,2689,1139,2882,2307,2867,2010,2375,2590,2508,2292,1637,1668,1627,2022,2340,2320,2033,1758,2034,3096,2993,2452,1963,1837,2063,1889,2131,1969,2181,4252,2258,2900,2008,2967,2143,1970,2261,1696,1838,1650,2000,1912,1632,2079,2011,2771,2526,2121,2137,2223,2099,1895,1985,1984,2455,2802,2256,3374,2282,2353,2097,1992,2177,2189,1994,4369,539]
                },
                {
                        "name": "tensorflow\/tensorflow",
                        "data": [0,0,0,0,0,0,0,0,0,0,14078,1931,2162,1492,1734,2290,2780,2207,1997,2038,2360,3034,2844,3344,3881,5164,4427,3633,3829,3525,3488,3588,3398,4318,5225,4802,4230,3359,4412,3592,3535,2829,2749,2404,2550,2596,2518,2202,2276,2081,3461,2820,2627,1910,2213,1853,2064,2010,2059,1658,1370,1284,1605,1638,1693,1407,1501,1294,1257,1214,1612,229]
                },
                {
                        "name": "vuejs\/vue",
                        "data": [0,0,0,0,0,0,0,0,0,1374,1562,1647,1711,1039,1416,2165,2188,1862,2219,2454,3010,3976,3497,3294,4100,4480,4622,3757,3816,3706,4193,3969,4252,4084,3677,3529,4662,3327,4601,3959,3687,11164,4032,3775,3004,2859,3237,3208,3486,2957,5579,4306,3630,3180,3248,2805,2316,2829,2422,2401,1850,2296,3061,3258,2569,2427,2727,2458,2679,1870,1856,407]

        ],

        "rows": 10,

        "statistics":
        {
                "elapsed": 0.657104025,
                "rows_read": 231481344,
                "bytes_read": 1581901060
        }
}
```

Notice the missing `}` after the last name/data tuple of the returned rows

Sadly i was not able to reproduce with a simpler statement or built in tables.

**Expected behavior**
There should be a `}`


Arguments common_arguments""};        /// 0th argument is ignored.
        std::vector<Arguments> 
        bool in_external_group = false;
        for (int arg_num = 1; arg_num < argc; ++arg_num)
        
            c arg = argv[arg_num];
            if (0 == strcmp(arg, "--external"))
            
                in_external_group = true;
                external_tables_arguments.emplace_back(Arguments""});
            }
            /// Options with value after equal sign.
            else if (in_external_group
                && (0 == strncmp(arg, "--file=", strlen("--file="))
                 || 0 == strncmp(arg, "--name=", strlen("--name="))
                 || 0 == strncmp(arg, "--format=", strlen("--format="))
                 || 0 == strncmp(arg, "--structure=", strlen("--structure="))
                 || 0 == strncmp(arg, "--types=", strlen("--types="))))
            
                external_tables_arguments.back().emplace_back(arg);
            }
            /// Options with value after whitespace.
            else if (in_external_group
                && (0 == strcmp(arg, "--file")
                 || 0 == strcmp(arg, "--name")
                 || 0 == strcmp(arg, "--format")
                 || 0 == strcmp(arg, "--structure")
                 || 0 == strcmp(arg, "--types")))
            
                if (arg_num + 1 < argc)