Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 17 min read Deep dive hardMaster

How we built a new powerful JSON data type for ClickHouse

ClickHouse's new JSON type stores every JSON path as a true columnar, dense subcolumn, built on two standalone building blocks: Variant and Dynamic. Variant keeps mixed-type values in per-type column files without coercing them to a common type, using a UInt8 discriminator column (255 reserved for NULL) and in-memory offsets to locate values. Dynamic removes the need to declare types up front and caps separately stored types with max_types (default 32). Types beyond the cap go into a binary-encoded SharedVariant string column, which keeps sparse or high-cardinality JSON from producing an avalanche of column files on disk.

Assumes: columnar storageClickHouse MergeTreeJSON data model

Related posts

  • Getting Data Into ClickHouse - Part 2 - A JSON detour

    ClickHouse mediumAdept

    ClickHouse's experimental JSON (Object('json')) type, introduced around 22.8, stores semi-structured rows by automatically inferring sub-columns and representing them internally as Tuples with minimal-width numeric types. It is demonstrated on the 28M-row Hacker News dataset via the JSONAsObject and JSONAsString formats. Because JSON sub-columns cannot serve as primary keys or carry codecs, the recommended pattern is a hybrid schema: declare stable fields like time and type explicitly so they can be used in ORDER BY, and keep the rest in a JSON column. That change cut a sample query from 2.6s to 0.74s. Inferred types widen transparently as new values arrive, but a single string value can silently convert a numeric column to String, so clean the data or declare critical columns explicitly.

  • ClickHouse Newsletter April 2022: JSON, JSON, JSON

    ClickHouse mediumAdept

    ClickHouse 22.3 LTS adds an experimental JSON data type that stores semi-structured documents in a single column, with dynamic subcolumns underneath, so you no longer need hand-built schemas of arrays and materialized columns. The worked examples cover querying nested fields, loading files with the JSONAsString format, and pulling a timestamp into its own column so MergeTree has a usable sorting key. They also show how to display field names with output_format_json_named_tuples_as_objects. The release also ships ARM Docker images, fully tested S3 disk storage (with known performance issues), and a Hive table function, and ClickHouse Cloud's serverless waitlist is now open.

  • ClickHouse Release 24.5

    ClickHouse mediumAdept

    ClickHouse 24.5 adds an experimental Dynamic data type for semi-structured columns that accepts values of any type without declaring them upfront like Variant, and queries them via dynamicType, dynamicElement and dot syntax. Reading files inside zip/tar archives now works for archives stored on S3, not just the local file system. CROSS JOIN memory usage is reworked: on a 1-billion-row PyPI table, peak memory fell from 51.77 GiB in 24.4 to 19.06 GiB uncompressed and 5.36 GiB with LZ4-compressed right-table blocks, at the cost of longer runtime. Right-table blocks can also spill to disk once max_bytes_in_join or max_rows_in_join is exceeded.

  • Making complex JSON 58x faster, use 3,300x less memory, in ClickHouse

    ClickHouse hardMaster

    ClickHouse v25.8 adds two new on-disk serializations for the JSON type's shared data, which holds paths beyond the 1,024 dynamic-subcolumn limit. Previously, reading such a path meant loading and filtering an entire Map(String, String) column. A bucketed format hashes paths into separate maps so only one bucket is read. An advanced format adds per-granule .structure, .paths_marks and substream files, so queries can skip granules and seek directly to a path or a nested subcolumn. To keep full-document reads and merges fast, the original map layout is stored alongside the advanced one, roughly doubling storage. On 200k rows with 10k paths, selective reads ran about 58x faster with about 3,300x less memory, and whole-document reads stayed close to the original format.

  • ClickHouse Release 24.8 LTS

    ClickHouse mediumAdept

    ClickHouse 24.8 is a Long Term Support release (supported for 12 months) with 19 new features, 18 performance optimisations and 65 bug fixes. Headline additions include an experimental JSON data type built on Variant and Dynamic, a table engine for time-series data, exactly-once processing of Kafka messages, and join improvements. The JSON type is shown in detail: dot syntax reads literal paths efficiently, `.^` returns subobjects, `.:Type` and `::Type` assume or cast types, and `SKIP`, `SKIP REGEXP` and per-path type hints control what is stored. A new `deduplicate_merge_projection_mode` setting controls how projections behave when ReplacingMergeTree or AggregatingMergeTree merges drop or fold rows. Previously, projections either silently fell out of sync or blocked those operations.

The quest for software engineering knowledge.

Look:
Layout: