1. Home
  2. Knowledge Base
  3. ClickHouse
  4. Utilizing JSON Feature in ClickHouse
  1. Home
  2. Knowledge Base
  3. ClickHouse Support
  4. Utilizing JSON Feature in ClickHouse

Utilizing JSON Feature in ClickHouse

ClickHouse offers an experimental JSON format. So we need to

SET allow_experimental_object_type = 1

Now, we may use the JSON type and insert JSON values while creating tables.

CREATE TABLE exp_test
(
    `id` UInt64,
    `value` JSON
)
ENGINE = MergeTree
ORDER BY id

INSERT INTO exp_test VALUES(1, '{"db_type":"ClickHouse","version":22.10}')
INSERT INTO exp_test VALUES(2, '{"db_type":"MongoDB","version":5}')
INSERT INTO exp_test VALUES(3, '{"db_type":"PostgreSQL","version":14}')
INSERT INTO exp_test VALUES(4, '{"db_type":"Oracle","version":19}')
INSERT INTO exp_test VALUES(5, '{"db_type":"MySQL","version":8}')

We can easily see the JSON values when we check the table. But there is no JSON columns with this way.

SELECT * FROM exp_test

┌─id─┬─value───────────────┐
│  1 │ ('ClickHouse',22.1) │
│  2 │ ('MongoDB',5)       │
│  3 │ ('PostgreSQL',14)   │
│  4 │ ('Oracle',19)       │
│  5 │ ('MySQL',8)         │
└────┴─────────────────────┘

Displaying JSON columns

SET output_format_json_named_tuples_as_objects = 1

When we look at the table, we can quickly notice the columns that contain the JSON values:

SELECT * FROM exp_test FORMAT JSONEachRow

{"id":"1","value":{"db_type":"ClickHouse","version":22.1}}
{"id":"2","value":{"db_type":"MongoDB","version":5}}
{"id":"3","value":{"db_type":"PostgreSQL","version":14}}
{"id":"4","value":{"db_type":"Oracle","version":19}}
{"id":"5","value":{"db_type":"MySQL","version":8}}

Was this article helpful?

Related Articles

CHISTADATA IS COMMITTED TO OPEN SOURCE SOFTWARE AND BUILDING HIGH PERFORMANCE COLUMNSTORES

In the spirit of freedom, independence and innovation. ChistaDATA Corporation is not affiliated with ClickHouse Corporation 

Need Support?

Can't find the answer you're looking for?
Contact Support

ChistaDATA Inc. Knowledge base is licensed under the Apache License, Version 2.0 (the “License”)

Copyright 2022 ChistaDATA Inc

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.