Format-Aware File I/O
Write objects to files and the format is chosen automatically based on the file extension. Read files and content is parsed back into structured data. Zero boilerplate.
Automatic Format Detection
File extensions determine the output format. Write to data.json and get JSON.
Write to data.csv and get CSV. It just works.
JSON / JSONL
Standard JSON or newline-delimited JSON Lines for streaming.
.json .jsonl .ndjson
YAML / TOML
Human-readable configuration formats with proper indentation.
.yaml .yml .toml
CSV / TSV
Spreadsheet-friendly formats with configurable delimiters.
.csv .tsv
XML / HTML
Markup formats with variable name as root element.
.xml .html .htm
Markdown / SQL
Tables for docs, INSERT statements for database backup.
.md .sql
Log Files
Date-prefixed log entries with ISO8601 timestamps.
.log
Environment
KEY=VALUE format with uppercase keys and underscore nesting.
.env
Plain Text / Binary
Key=value format or raw binary data.
.txt .obj
Writing Structured Data
Simply write your data to a file path. The extension determines the format automatically.
JSON and JSON Lines
(* Pretty-printed JSON *)
Write the <users> to "./output/users.json".
(* JSON Lines - one object per line, compact *)
Write the <events> to "./logs/events.jsonl".
JSON output:
[
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]
JSONL output:
{"id":1,"name":"Alice"}
{"id":2,"name":"Bob"}
YAML and TOML
(* YAML - human readable *)
Write the <config> to "./settings.yaml".
(* TOML - configuration files *)
Write the <config> to "./settings.toml".
CSV and TSV
(* CSV with header row *)
Write the <report> to "./export/report.csv".
(* TSV - tab separated *)
Write the <data> to "./export/data.tsv".
CSV output:
id,name,email
1,Alice,alice@example.com
2,Bob,bob@example.com
XML
(* XML - variable name becomes root element *)
Write the <products> to "./catalog/products.xml".
XML output: (note: <products> is the root)
<?xml version="1.0" encoding="UTF-8"?>
<products>
<item>
<id>1</id>
<name>Widget</name>
</item>
</products>
Other Formats
(* Markdown table *)
Write the <summary> to "./docs/summary.md".
(* HTML table *)
Write the <report> to "./output/report.html".
(* SQL INSERT statements *)
Write the <users> to "./backup/users.sql".
(* Log file with timestamp *)
Write the <message> to "./app.log" with "Server started".
(* Environment file - uppercase keys with underscore nesting *)
Write the <config> to "./.env".
(* Plain text key=value *)
Write the <config> to "./output/config.txt".
Reading Structured Data
When reading files, the extension determines how content is parsed back into structured data.
(* JSON - parsed to object/array *)
Read the <config> from "./settings.json".
(* JSONL - parsed to array of objects *)
Read the <events> from "./logs/events.jsonl".
(* CSV - parsed to array with headers as keys *)
Read the <records> from "./data.csv".
(* YAML - parsed to object/array *)
Read the <settings> from "./config.yaml".
Bypass Parsing with as String
(* Read raw content without parsing *)
Read the <raw-json: String> from "./data.json".
Format Reference
| Extension | Format | Write Output | Read Result |
|---|---|---|---|
.json |
JSON | Pretty-printed JSON | Object or Array |
.jsonl .ndjson |
JSON Lines | One JSON object per line | Array of Objects |
.yaml .yml |
YAML | Human-readable YAML | Object or Array |
.toml |
TOML | TOML tables | Object |
.xml |
XML | XML with variable as root | Object (nested) |
.csv |
CSV | Comma-separated with header | Array of Objects |
.tsv |
TSV | Tab-separated with header | Array of Objects |
.md |
Markdown | Markdown table | String |
.html .htm |
HTML | HTML table element | String |
.txt |
Plain Text | key=value pairs | Object |
.sql |
SQL | INSERT statements | String |
.log |
Log | Date-prefixed entries | String |
.env |
Environment | KEY=VALUE format | Object |
.obj or unknown |
Binary | Raw bytes | Binary Data |
URL Format Detection
When reading from URLs (see HTTP Services), the format is
detected from the HTTP Content-Type header instead of the file extension.
| Content-Type | Detected Format |
|---|---|
application/json |
JSON |
application/x-ndjson |
JSON Lines |
text/csv, application/csv |
CSV |
text/tab-separated-values |
TSV |
text/yaml, application/x-yaml |
YAML |
application/xml, text/xml |
XML |
text/html |
HTML |
text/plain |
Plain Text |
(* JSON API - auto-parsed based on Content-Type header *)
Read the <users> from the <url: "https://api.example.com/users">.
(* users is now a structured object *)
Extract the <name> from the <users: 0.name>.
(* Bypass parsing with as String *)
Read the <raw: String> from the <url: "https://api.example.com/users">.
CSV/TSV Options
CSV and TSV formats support additional options via the with clause:
| Option | Type | Default | Description |
|---|---|---|---|
delimiter |
String | , / \t |
Field separator character |
header |
Boolean | true |
Include/expect header row |
quote |
String | " |
Quote character for escaping |
(* Custom delimiter *)
Write the <data> to "./export.csv" with { delimiter: ";" }.
(* Without header row *)
Write the <data> to "./export.csv" with { header: false }.
(* Read with custom options *)
Read the <data> from "./import.csv" with { delimiter: ";" }.
Complete Example
Here's a complete example that reads data from one format and exports to multiple formats:
(Application-Start: Multi-Format Export) {
(* Create sample data *)
Create the <users> with [
{ "id": 1, "name": "Alice", "email": "alice@example.com" },
{ "id": 2, "name": "Bob", "email": "bob@example.com" },
{ "id": 3, "name": "Charlie", "email": "charlie@example.com" }
].
(* Export to multiple formats - same data, different files *)
Write the <users> to "./output/users.json".
Write the <users> to "./output/users.jsonl".
Write the <users> to "./output/users.yaml".
Write the <users> to "./output/users.csv".
Write the <users> to "./output/users.xml".
Write the <users> to "./output/users.md".
Log "Exported to 6 formats!" to the <console>.
(* Read back and verify *)
Read the <json-data> from "./output/users.json".
Read the <csv-data> from "./output/users.csv".
Return an <OK: status> for the <export>.
}
Learn More
See the full format-aware I/O specification in ARO-0040: Format-Aware File I/O.