Skip to Content
Fetlar
Using Fetlar

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.csv

Without 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:

KeyMeaning
vthe value
tdate for an ISO date, text to keep a number as text, number for a numeric string
fa formula. v is its saved result
fmta number format, such as #,##0.00 or 0%
bold italic underline strike size font color filltext and cell style. fill and color are RRGGBB
align valign wrap indent rotate rtlplacement and direction
border border_color lockedborders 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

OptionMeaning
-o, --output OUTthe output file. - writes to standard output
--delimiter CHARCSV separator: one character, or tab
--no-bomno byte order mark
--lfend rows with LF instead of CRLF
--encodingutf-8 or utf-16le
--guard-formulasCSV: prefix ' to fields that start with =, +, -, @, tab or CR, so a spreadsheet does not run them as formulas
--shared-stringsXLSX: one shared string table instead of text in each cell
--compression 0-9XLSX and DOCX: compression level. Default 4
--large-fileallow a part over 4 GB
--safeDOCX: 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.

On this page