Skip to main content

Module jsonl

Module jsonl 

Source
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.5 and "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": 1704067200000 is an epoch in milliseconds for a millisecond column — there is no unit conversion, and "ts": 1704067200 means 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§

JsonStringState 🔒
Only distinguishes string content from discarded JSON whitespace. Syntax validation and record boundaries remain entirely arrow-json’s job.
JsonlCodec 🔒
The validated jsonl format configuration.
JsonlRecordParser 🔒
Incremental parser backed by arrow-json’s decoder. Unlike arrow-csv, a record finalizes as soon as its closing } is parsed, and a single flush drains and clears the buffered tape — so there is no EOF signal to send at CopyDone.

Constants§

TOP_LEVEL_ARRAY_HINT 🔒

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.rs does. A field value that does not decode against its column type is an invalid text representation (22P02): arrow-json wraps those as JsonError("whilst decoding field '<name>': …") (see its struct_array.rs), since it has no separate ParseError for them. JSON syntax errors (truncated records, unexpected tokens) and anything else is bad copy data (22P04) — never an internal XX000.
is_json_whitespace 🔒
arrow-json’s whitespace set, which Decoder::decode skips freely.