Writing files
Make Word, Excel and CSV files from JSON.
fetlar write turns a JSON file into a Word, Excel or CSV file.
fetlar write report.json -o report.docx
fetlar write budget.json -o budget.xlsx
fetlar write names.json -o names.csvWithout a kind in the JSON, the extension of the output file decides.
Excel
{
"kind": "xlsx",
"sheets": [
{
"name": "Budget 2027",
"cols": [{"width": 22}, {"width": 14}],
"rows": [
[{"v": "Item", "bold": true}, {"v": "Amount", "bold": true}],
["Salaries", {"v": 120000, "fmt": "#,##0.00"}],
["Rent", {"v": 125000, "fmt": "#,##0.00"}],
["Growth", {"v": 0.15, "fmt": "0%"}],
["Date", {"v": "2026-03-01", "t": "date", "fmt": "dd/mm/yyyy"}],
["Total", {"f": "SUM(B2:B3)", "v": 245000, "fmt": "#,##0.00"}]
]
}
]
}A cell is a string, number, boolean, null, or an object:
| Key | Meaning |
|---|---|
v | the value |
t | date for an ISO date, text to keep a number as text, number for a numeric string |
f | a formula. v is its saved result |
fmt | a number format, such as #,##0.00 or 0% |
bold italic underline strike size font color fill | text and cell style. fill and color are RRGGBB |
align valign wrap indent rotate rtl | placement and direction |
border border_color locked | borders and protection |
A row is a list of cells, or an object like {"cells": [...], "height": 30, "hidden": true}.
A sheet takes name, rtl, freeze, cols, merges, autofilter, state (hidden), tab_color and gridlines. The file takes properties (title, author, subject, keywords, comments, company, created) and date1904.
Reading the file back gives the values as Excel shows them:
## Budget 2027
| Item | Amount |
|---|---|
| Salaries | 120,000.00 |
| Rent | 125,000.00 |
| Growth | 15% |
| Date | 01/03/2026 |
| Total | 245,000.00 |Prefer Excel to CSV
Use .xlsx for Arabic or other non-Latin text, leading zeros, long digit strings, dates, formulas and several sheets. Excel strips leading zeros and reformats long numbers and dates in a CSV.
Word
{
"kind": "docx",
"properties": {"title": "Supply agreement", "author": "Legal"},
"blocks": [
{"type": "heading", "level": 1, "text": "Supply agreement"},
{"type": "heading", "level": 2, "text": "4.2 Payment terms"},
{"type": "paragraph", "text": "Payment within 30 days of invoice."},
{"type": "list_item", "ordered": true, "text": "Approve the budget"},
{"type": "table", "header_rows": 1, "rows": [["Item", "Amount"], ["Salaries", "1,234,567.89"]]}
]
}Blocks are heading (with level), paragraph, list_item (ordered, level, num_format, list), table (rows, header_rows, widths, merges, borders, rtl), image (src, width_in, height_in, alt), toc and page_break.
A paragraph takes text or runs. A run can be bold, italic, underlined, colored, a link, a footnote, a field such as PAGE, and more. The file also takes styles, lists, defaults, headers, footers, and sections for page setup.
Run fetlar write --help for every key. A key the writer does not know exits with code 3, so a typo never passes silently.
Word files open without a repair prompt.
CSV and TSV
{"kind": "csv", "rows": [["الاسم", "المدينة"], ["علي", "الرياض"]]}Cells are strings, numbers, booleans (TRUE or FALSE) or null (empty). Kind tsv uses tabs.
By default a byte order mark is written, so Excel reads Arabic correctly. --no-bom removes it. Excel then garbles non-Latin text.
Options
| Option | Meaning |
|---|---|
-o, --output OUT | the output file. - writes to standard output |
--delimiter CHAR | CSV separator: one character, or tab |
--no-bom | no byte order mark |
--lf | end rows with LF instead of CRLF |
--encoding | utf-8 or utf-16le |
--guard-formulas | CSV: prefix ' to fields that start with =, +, -, @, tab or CR, so a spreadsheet does not run them as formulas |
--shared-strings | XLSX: one shared string table instead of text in each cell |
--compression 0-9 | XLSX and DOCX: compression level. Default 4 |
--large-file | allow a part over 4 GB |
--safe | DOCX: only safe fields and http, https and mailto links. Use it for content you do not trust |
The output is written to a temporary file and renamed when complete. A failed write never leaves half a file and never destroys an existing one.
--safe does not stop pictures from being read from paths next to the JSON file. Do not use JSON that names files you do not want embedded.
From an AI assistant
The MCP tool write_office_file does the same, inside a folder you allow. See MCP tools.