JSON
JSON is a complex data type provided by VeloDB Cloud. It stores JSON data efficiently in a binary format and provides JSON functions to access internal fields. Choose this type when your business needs to store semi-structured data such as event tracking logs, user attributes, or configuration items, and requires fast access to internal fields.
Compared with storing JSON strings as the String type, the JSON type offers the following advantages:
- Data validation: VeloDB Cloud automatically validates JSON format on write, rejecting invalid JSON syntax.
- Field access: Functions such as
JSON_EXTRACT()access values in the parsed binary representation. Storage size and query performance depend on the data and queries.
Capacity limits
| Item | Core 26.1.3 implementation reference | Warehouse guidance |
|---|---|---|
| Size of a stored JSON value | The compiled string_type_length_soft_limit_bytes is 10 MiB (10,485,760 bytes). The configuration validator permits up to 2,147,483,643 bytes. | This is a limit on the binary value, not a guaranteed source-file size or warehouse setting. Contact VeloDB Cloud support to confirm the effective limit or request a change. |
Before you start
Create or select the target database, and use a warehouse SQL user with the required table and load permissions. Copy the Stream Load request URL from Connection Methods. Replace <endpoint> with its scheme, host, and port, and preserve HTTPS when it is required. Replace <username> with your warehouse SQL username. The curl commands prompt for your password.
Choose one input-format procedure for each sample table, or recreate the sample table before trying another procedure. The displayed rows and timings illustrate the source examples. They are not measurements from your warehouse.
Choose an import method
Choose an import option based on the format of your source data file:
| Source File Format | Use Case | Key Parameters |
|---|---|---|
| CSV | Data comes from a delimited file with one record per line | column_separator (a non-comma delimiter such as | is recommended) |
| JSON | Data is already in JSON array or JSON Lines format | format:json, strip_outer_array:true |
The following sections use Stream Load as an example to walk through the complete import process for both methods.
Load CSV data
Step 1: Prepare the data
Create a CSV file test_json.csv. Because JSON internally uses commas to separate fields, use | as the column delimiter to avoid conflicts:
1|{"name": "tom", "age": 35}
2|{"name": null, "age": 28}
3|{"name": "micheal", "age": null}
4|{"name": null, "age": null}
5|null
Step 2: Create a table in the database
CREATE TABLE json_test (
id INT NOT NULL,
c_json JSON NULL
)
DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 1;
Step 3: Import the data
Submit a Stream Load job. Set the column delimiter to | with column_separator:
curl --location-trusted \
-u "<username>" \
-H "column_separator:|" \
-H "columns: id, c_json" \
-T "test_json.csv" \
"<endpoint>/api/testdb/json_test/_stream_load"
Step 4: Verify the imported data
SELECT * FROM json_test;
+------+-------------------------------+
| id | c_json |
+------+-------------------------------+
| 1 | {"name":"tom","age":35} |
| 2 | {"name":null,"age":28} |
| 3 | {"name":"micheal","age":null} |
| 4 | {"name":null,"age":null} |
| 5 | null |
+------+-------------------------------+
5 rows in set (0.01 sec)
Load JSON data
Step 1: Prepare the data
Create a JSON file test_json.json. The file content is a JSON array, where each element corresponds to one row of records:
[
{"id": 1, "c_json": {"name": "tom", "age": 35}},
{"id": 2, "c_json": {"name": null, "age": 28}},
{"id": 3, "c_json": {"name": "micheal", "age": null}},
{"id": 4, "c_json": {"name": null, "age": null}},
{"id": 5, "c_json": null}
]
Step 2: Create a table in the database
CREATE TABLE json_test (
id INT NOT NULL,
c_json JSON NULL
)
DUPLICATE KEY(id)
DISTRIBUTED BY HASH(id) BUCKETS 1;
Step 3: Import the data
Submit a Stream Load job. Set format:json, and use strip_outer_array:true to unwrap the outer array:
curl --location-trusted \
-u "<username>" \
-H "format:json" \
-H "columns: id, c_json" \
-H "strip_outer_array:true" \
-T "test_json.json" \
"<endpoint>/api/testdb/json_test/_stream_load"
Step 4: Verify the imported data
mysql> SELECT * FROM json_test;
+------+-------------------------------+
| id | c_json |
+------+-------------------------------+
| 1 | {"name":"tom","age":35} |
| 2 | {"name":null,"age":28} |
| 3 | {"name":"micheal","age":null} |
| 4 | {"name":null,"age":null} |
| 5 | NULL |
+------+-------------------------------+
5 rows in set (0.01 sec)
FAQ
Q1: What is the maximum size of a JSON field?
The Core 26.1.3 implementation reference is a 10 MiB compiled limit on the binary value. The effective warehouse setting can differ. See Capacity limits, and contact VeloDB Cloud support before loading larger values. Do not edit managed backend configuration.
Q2: How should you handle legacy Apache Doris JSONB schemas?
Use JSON in new schemas. For an existing Apache Doris schema that uses JSONB, validate its DDL and representative data against the target warehouse before migration.
Q3: Why is the JSON type recommended over String for storing JSON?
The JSON type validates the format on write, rejecting invalid JSON syntax. This does not validate business rules. Its binary representation supports field access through JSON functions without treating the value as an arbitrary string. Measure storage and query performance for your workload.
Q4: Why use the | delimiter when importing CSV?
Without suitable enclosing and escape settings, commas inside JSON conflict with a comma column delimiter. Choose a character that does not appear in the JSON strings (such as |) as the column delimiter.
Q5: Why is strip_outer_array:true required when importing a JSON array?
This parameter tells Stream Load to unwrap the outer JSON array and import each element of the array as an independent row. Without it, an outer array is rejected by the JSON reader.
Common errors
- Authentication or connection failure: Check the generated warehouse endpoint, TLS requirements, SQL user permissions, and network access. For remote files, also check source credentials and reachability.
- Filtered rows or parsing errors: Check the input format, delimiters, field mappings, and target column types. Inspect the returned load error before retrying. Raising the filter tolerance can discard data.
- Unexpected duplicate rows: These examples use independent loads. Check the table model and existing rows before rerunning a sample.