export.csvTree
The account tree as CSV text, as GnuCash's CSV export writes it. Writes no file.
Returns the account tree as CSV text, in the layout of GnuCash's Export Account Tree to CSV, which GnuCash's and
red-ale's account import read back. It writes no file: the text is in csv, with rows for
the number of accounts. Fields are quoted only when they hold the separator, a quote or a line break, unless quotes
is set. Siblings come in book order but are sorted by name bytewise, where GnuCash sorts by locale.
Examples
Example: with a new, empty book open as book.gnucash.
JSON-RPC
Request:
{"jsonrpc":"2.0","id":1,"method":"account.create","params":{"name":"Checking","type":"BANK","commodity":"USD"}}
Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": "…"
}
Request:
{"jsonrpc":"2.0","id":2,"method":"export.csvTree","params":{}}
Response:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"csv": "Type,Full Account Name,Account Name,Account Code,Description,Account Color,Notes,Symbol,Namespace,Hidden,Tax Info,Placeholder\r\nBANK,Checking,Checking,,,,,USD,CURRENCY,F,F,F\r\n",
"rows": 1
}
}
Command line
red-ale exec --book book.gnucash --script - <<'EOF'
account.create {"name":"Checking","type":"BANK","commodity":"USD"}
export.csvTree {}
EOF
It prints:
[
"…",
{
"csv": "Type,Full Account Name,Account Name,Account Code,Description,Account Color,Notes,Symbol,Namespace,Hidden,Tax Info,Placeholder\r\nBANK,Checking,Checking,,,,,USD,CURRENCY,F,F,F\r\n",
"rows": 1
}
]
MCP tool call
Tool call:
{"name":"account.create","arguments":{"name":"Checking","type":"BANK","commodity":"USD"}}
Result:
{
"content": [
{
"type": "text",
"text": "\"…\""
}
]
}
Tool call:
{"name":"export.csvTree","arguments":{}}
Result:
{
"structuredContent": {
"csv": "Type,Full Account Name,Account Name,Account Code,Description,Account Color,Notes,Symbol,Namespace,Hidden,Tax Info,Placeholder\r\nBANK,Checking,Checking,,,,,USD,CURRENCY,F,F,F\r\n",
"rows": 1
}
}
Effect: read.
Params
Params of export.csvTree.
separator(string): The field separator: any non-empty string.quotes(boolean): Quote every field. Without it, a field is quoted only when it holds the separator, a quote or a line break.
Result
The result of export.csvTree.
csv(string, required): The CSV text: UTF-8, every line ending in CRLF, the header first.rows(integer (uint), required): Account lines, the header not counted.