toon_codec/encode/arrays
Array encoding functions.
This module handles encoding of JSON arrays to TOON format, including:
- Inline primitive arrays
- Tabular arrays (uniform objects)
- Arrays of arrays
- Mixed/complex arrays (expanded list form) Encode an array to TOON format.
Automatically detects the best representation:
- Empty arrays:
key[0]: - Primitive arrays: inline format
key[N]: v1,v2,v3 - Arrays of primitive arrays: expanded list with inline subarrays
- Uniform objects with primitive values: tabular format
- Mixed/complex: expanded list format
Arguments
key- Optional key name (None for root arrays)values- The array elementswriter- The line writerdepth- Current indentation depthoptions- Encoding options Encode a primitive array in inline format.
Examples
tags[3]: admin,ops,dev
Encode an array of primitive arrays in expanded list format.
Examples
pairs[2]:
- [2]: 1,2
- [2]: 3,4
Encode an array of uniform objects in tabular format.
Examples
users[2]{id,name}:
1,Alice
2,Bob
Encode a mixed/complex array in expanded list format.
Examples
items[3]:
- 1
- a: 1
- text
Encode a single list item (element in expanded array). Encode a complex array as a list item. Encode an object as a list item.
The first field appears on the hyphen line, remaining fields at depth + 1. Encode the first field of an object on the hyphen line. Encode object fields (helper for encoding remaining fields). Encode a key-value pair at a specific depth.
Values
pub fn encode_array(
key: option.Option(String),
values: List(types.JsonValue),
writer: writer.Writer,
depth: Int,
options: types.EncodeOptions,
) -> writer.Writer