| 862 | } |
| 863 | |
| 864 | void registerDataTypeJSON(DataTypeFactory & factory) |
| 865 | { |
| 866 | factory.registerDataType("JSON", createJSON, DataTypeFactory::Case::Insensitive, Documentation{ |
| 867 | .description = String(R"DOCS_MD( |
| 868 | :::tip |
| 869 | Check out our [JSON best practice guide](/docs/best-practices/use-json-where-appropriate) for examples, advanced features and considerations for using the JSON type. |
| 870 | ::: |
| 871 | |
| 872 | The `JSON` type stores JavaScript Object Notation (JSON) documents in a single column. |
| 873 | |
| 874 | :::note |
| 875 | In ClickHouse Open-Source JSON data type is marked as production ready in version 25.3. It's not recommended to use this type in production in previous versions. |
| 876 | ::: |
| 877 | |
| 878 | To declare a column of `JSON` type, you can use the following syntax: |
| 879 | |
| 880 | ```sql |
| 881 | <column_name> JSON |
| 882 | ( |
| 883 | max_dynamic_paths=N, |
| 884 | max_dynamic_types=M, |
| 885 | some.path TypeName, |
| 886 | SKIP path.to.skip, |
| 887 | SKIP REGEXP 'paths_regexp' |
| 888 | ) |
| 889 | ``` |
| 890 | Where the parameters in the syntax above are defined as: |
| 891 | |
| 892 | | Parameter | Description | Default Value | |
| 893 | |-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| |
| 894 | | `max_dynamic_paths` | An optional parameter indicating how many paths can be stored separately as sub-columns across single block of data that is stored separately (for example across single data part for MergeTree table). <br/><br/>If this limit is exceeded, all other paths will be stored together in a single structure called [shared data](#shared-data-structure).<br/><br/>There are also [ways](#controlling-the-number-of-dynamic-paths) how to change the limit on dynamic paths without changing this parameter. | `1024` | |
| 895 | | `max_dynamic_types` | An optional parameter between `1` and `255` indicating how many different data types can be stored separately inside a single path column with type `Dynamic` across single block of data that is stored separately (for example across single data part for MergeTree table). <br/><br/>If this limit is exceeded, all new types will be stored together in a single structure called `shared variant`. | `32` | |
| 896 | | `some.path TypeName` | An optional type hint for particular path in the JSON. Such paths will be always stored as sub-columns with specified type. | | |
| 897 | | `SKIP path.to.skip` | An optional hint for particular path that should be skipped during JSON parsing. Such paths will never be stored in the JSON column. If specified path is a nested JSON object, the whole nested object will be skipped. | | |
| 898 | | `SKIP REGEXP 'path_regexp'` | An optional hint with a regular expression that is used to skip paths during JSON parsing. All paths that match this regular expression will never be stored in the JSON column. | | |
| 899 | |
| 900 | ## Creating `JSON` {#creating-json} |
| 901 | |
| 902 | In this section we'll take a look at the various ways that you can create `JSON`. |
| 903 | |
| 904 | ### Using `JSON` in a table column definition {#using-json-in-a-table-column-definition} |
| 905 | |
| 906 | ```sql title="Query (Example 1)" |
| 907 | CREATE TABLE test (json JSON) ENGINE = Memory; |
| 908 | INSERT INTO test VALUES ('{"a" : {"b" : 42}, "c" : [1, 2, 3]}'), ('{"f" : "Hello, World!"}'), ('{"a" : {"b" : 43, "e" : 10}, "c" : [4, 5, 6]}'); |
| 909 | SELECT json FROM test; |
| 910 | ``` |
| 911 | |
| 912 | ```text title="Response (Example 1)" |
| 913 | ┌─json────────────────────────────────────────┐ |
| 914 | │ {"a":{"b":"42"},"c":["1","2","3"]} │ |
| 915 | │ {"f":"Hello, World!"} │ |
| 916 | │ {"a":{"b":"43","e":"10"},"c":["4","5","6"]} │ |
| 917 | └─────────────────────────────────────────────┘ |
| 918 | ``` |
| 919 | |
| 920 | ```sql title="Query (Example 2)" |
| 921 | CREATE TABLE test (json JSON(a.b UInt32, SKIP a.e)) ENGINE = Memory; |
no test coverage detected