Reshape a document while translating it

Run an alchemy program over the input with --with, and write what it returns in the target format.

The document you have is not the shape you need, and the shape you need is in another format. --with runs an alchemy program over the input first, then writes the program's result in the target format.

Write the program #

The program's export must return a document or a table. table.alc returns a table of the records in records.json, with the columns the document describes. Write your first program builds it step by step.

Run it in the translation #

Name the program with --with:

$ dmog translate --from json --to csv --with table.alc records.json
"Identifier","Full name","Balance"
"123","Alice","50.25"
"456","Bob","72"
$ dmog translate --from json --to jsonl --with table.alc records.json
{"Identifier":123,"Full name":"Alice","Balance":50.25}
{"Identifier":456,"Full name":"Bob","Balance":72}

The same program serves every target. A table written to a tree format becomes an array of objects, one for each row.

What to watch for #

A program that writes its own text, such as one that ends in json input or csv, cannot be used here, because the target format does the writing. dmog refuses it with DSL_TYPE_ERROR and the finer code bad_output. Return the events or the table instead, and let --to choose the text.

The program reads the input as the format --from names, so one program works over a JSON, YAML, or TOML document of the same shape. For what a program can return, see --with.

This page describes dmog 0.4.0. Edit this page · This page as Markdown