Expand description
The jsonl format: newline-delimited JSON objects, one per record.
Parsing and typed conversion both reuse arrow-json’s incremental
Decoder — the engine behind
GreptimeDB’s file-based COPY ... FROM 'file.json' (see
common-datasource‘s json file format) — so both COPY routes
accept identical data. The decoder splits records (objects may span
chunk boundaries; pretty-printed multi-line objects and concatenated
{...}{...} streams are accepted too) and converts fields against
the targeted columns’ schema in one pass; a record is one JSON
object whose keys address the columns by name (the COPY column
list fixes the target order, as with csv).
What the engine actually accepts, so the rules match the behavior rather than a strict reading of the column types:
- Numeric columns take JSON numbers or numeric strings
(
"val": 1.5and"val": "1.5"both decode); booleans must be JSON booleans ("b": "true"is rejected). - Timestamps are date-time strings (RFC 3339; offset-free ones parse
in the session timezone, like SQL INSERT) or numbers, taken as
the column’s time unit verbatim:
"ts": 1704067200000is an epoch in milliseconds for a millisecond column — there is no unit conversion, and"ts": 1704067200means 1970-01-20 in that column. A quoted number is parsed as a date-time string and so fails. - Keys outside the column list are ignored, so a misspelled key
(
"hots") yields NULL in its column instead of an error, and records may carry more keys than a column subset selects. (arrow-json’s strict mode would change the first half of that but also reject the second, so it stays off.) - Absent keys become NULL; a NULL in a non-nullable column (such as the time index) is rejected with a message naming the column.
- Column types arrow-json cannot decode (JSON, Binary) are rejected up front.
The format is table-bound like csv and takes no options; the
file-based json format’s layout options are writer-side only, and
arrow-json’s reader parses date-time strings natively (RFC 3339,
with the schema’s timezone for offset-free strings). json is an
alias for jsonl, matching the file-based format’s name; it still
means newline-delimited objects — a top-level JSON array [{...}]
is rejected with a specific hint.
Structs§
- Json
String 🔒State - Only distinguishes string content from discarded JSON whitespace. Syntax validation and record boundaries remain entirely arrow-json’s job.
- Jsonl
Codec 🔒 - The validated
jsonlformat configuration. - Jsonl
Record 🔒Parser - Incremental parser backed by arrow-json’s decoder. Unlike
arrow-csv, a record finalizes as soon as its closing
}is parsed, and a singleflushdrains and clears the buffered tape — so there is no EOF signal to send atCopyDone.
Constants§
Functions§
- build_
jsonl_ 🔒codec - Builds the codec from the parsed options.
- decode_
error 🔒 - Maps arrow-json errors to PostgreSQL’s COPY error classes, the
way
csv.rsdoes. A field value that does not decode against its column type is an invalid text representation (22P02): arrow-json wraps those asJsonError("whilst decoding field '<name>': …")(see itsstruct_array.rs), since it has no separateParseErrorfor them. JSON syntax errors (truncated records, unexpected tokens) and anything else is bad copy data (22P04) — never an internalXX000. - is_
json_ 🔒whitespace - arrow-json’s whitespace set, which
Decoder::decodeskips freely.