ClickHouse/docs/en/formats/json.rst

86 lines
3.2 KiB
ReStructuredText
Raw Normal View History

2017-04-03 19:49:50 +00:00
JSON
-----
2017-04-26 18:02:30 +00:00
Outputs data in JSON format. Besides data tables, it also outputs column names and types, along with some additional information - the total number of output rows, and the number of rows that could have been output if there weren't a LIMIT. Example:
2017-04-03 19:49:50 +00:00
.. code-block:: sql
SELECT SearchPhrase, count() AS c FROM test.hits GROUP BY SearchPhrase WITH TOTALS ORDER BY c DESC LIMIT 5 FORMAT JSON
{
"meta":
[
{
"name": "SearchPhrase",
"type": "String"
},
{
"name": "c",
"type": "UInt64"
}
],
"data":
[
{
"SearchPhrase": "",
"c": "8267016"
},
{
"SearchPhrase": "интерьер ванной комнаты",
"c": "2166"
},
{
"SearchPhrase": "яндекс",
"c": "1655"
},
{
"SearchPhrase": "весна 2014 мода",
"c": "1549"
},
{
"SearchPhrase": "фриформ фото",
"c": "1480"
}
],
"totals":
{
"SearchPhrase": "",
"c": "8873898"
},
"extremes":
{
"min":
{
"SearchPhrase": "",
"c": "1480"
},
"max":
{
"SearchPhrase": "",
"c": "8267016"
}
},
"rows": 5,
"rows_before_limit_at_least": 141137
}
2017-04-26 18:02:30 +00:00
JSON is compatible with JavaScript. For this purpose, certain symbols are additionally escaped: the forward slash ``/`` is escaped as ``\/``; alternative line breaks ``U+2028`` and ``U+2029``, which don't work in some browsers, are escaped as \uXXXX-sequences. ASCII control characters are escaped: backspace, form feed, line feed, carriage return, and horizontal tab as ``\b``, ``\f``, ``\n``, ``\r``, and ``\t`` respectively, along with the rest of the bytes from the range 00-1F using \uXXXX-sequences. Invalid UTF-8 sequences are changed to the replacement character ``<EFBFBD>`` and, thus, the output text will consist of valid UTF-8 sequences. UInt64 and Int64 numbers are output in double quotes for compatibility with JavaScript.
2017-04-03 19:49:50 +00:00
2017-04-26 18:02:30 +00:00
``rows`` - The total number of output rows.
2017-04-03 19:49:50 +00:00
2017-04-26 18:02:30 +00:00
``rows_before_limit_at_least`` - The minimal number of rows there would have been without a LIMIT. Output only if the query contains LIMIT.
2017-04-03 19:49:50 +00:00
2017-04-26 18:02:30 +00:00
If the query contains GROUP BY, ``rows_before_limit_at_least`` is the exact number of rows there would have been without a LIMIT.
2017-04-03 19:49:50 +00:00
2017-04-26 18:02:30 +00:00
``totals`` - Total values (when using WITH TOTALS).
2017-04-03 19:49:50 +00:00
2017-04-26 18:02:30 +00:00
``extremes`` - Extreme values (when extremes is set to 1).
This format is only appropriate for outputting a query result, not for parsing.
See JSONEachRow format for INSERT queries.