Skip to main content

Module nested_json

Module nested_json 

Source
Expand description

List, array and struct cells as JSON text, for the destinations that hold one value per field: a CSV export and every clipboard copy. JSON rather than the table’s own rendering ([1, 2], {1,"a"}) because it keeps struct field names and reads back with any JSON parser, Polars’ str.json_decode included.

The text is Polars’ own JSON writer, the one NDJSON export uses, so a list reads the same in a CSV as in a .jsonl written from the same view.

Binary has no JSON or CSV form, and Polars’ JSON writer panics on it, so it is written as standard base64 text wherever it sits: a CSV, JSON or NDJSON export and a copy all spell the same bytes the same way.

Polars’ writers also panic on a date or datetime past the calendar’s range (a sentinel like i64::MIN + 1 microseconds), so dates and millisecond and microsecond datetimes are given to them as the text they would write, and such a value as its stored number, as the table shows it. A nanosecond count is always a date and goes to the writers as it is.

A duration has no CSV form either, and is written as the JSON writer spells it: ISO 8601 in seconds (PT3723.004S, -PT1.5S, P0D). That is exact to the nanosecond in every unit, and reads the same alone in a CSV cell or a copy, inside a list, and in a JSON export.

Enums§

Writer
The writer whose text for a date or datetime calendar_as_text writes.

Functions§

calendar_as_text
A date or datetime column as the text writer writes for it, with its nulls; a value past the calendar’s range, on which the writers panic, as its stored number (crate::exact::out_of_range), as the table shows it.
column_as_json
One nested column as a String column of JSON, null where the value is null.
duration_as_iso
A duration column as a String column of duration_iso text, with its nulls.
duration_iso
value units as ISO 8601 text, the way Polars’ JSON writer spells a duration (chrono’s TimeDelta display): whole seconds and the fraction’s significant digits, P0D for zero, a leading - when negative. Computed here rather than through chrono, whose range ends short of i64::MIN ms.
frame_as_cells
frame_as_json with dates and datetimes kept in their own type: the cells a Markdown or HTML copy writes through crate::exact::value_text, which spells one past the calendar as its stored number itself.
frame_as_json
lazy_as_json for frames already in memory: a copy’s rows, as the CSV writer takes them.
has_binary
Whether dtype is binary or has binary anywhere inside.
is_nested
Whether a column is a list, array or struct, which a delimited writer takes only as JSON text.
lazy_as_json
lf with every column a CSV writer cannot take (needs_text) replaced by its text, in place and under its own name: what a CSV export writes. Planned, not run: the text is built as the rows are collected.
lazy_for_json
lf with every column that has binary, a date or a datetime in it as text (leaves_as_json_text), in place and under its own name: what a JSON export writes. Planned, not run.
leaves_as_json_text
series with every binary value, at any depth, as its base64 text, and every date and datetime as the JSON writer’s text (calendar_as_text). Lists, arrays and structs keep their shape and their nulls.
needs_text
Whether a column needs to become text before a CSV writer takes it: it is nested, binary, a duration, or a date or datetime in ms or us, which the writer can panic on.