Translate a document that cannot be streamed

Use --whole for a document with a repeated key or several YAML documents, which dmog cannot write as it reads.

dmog writes as it reads, and a few documents can't be written that way. A repeated key is one: the format's own reading keeps one of the two values, and which one is only known once both have been read. A YAML stream of several documents is another, because it has more than one root. dmog refuses these and names --whole in the message.

Recognise the refusal #

Here a JSON object holds the key name twice:

$ cat repeated.json
{"name":"first","name":"second"}
$ dmog translate --from json --to yaml repeated.json; echo $?
{"code":"DUPLICATE_MEMBER","message":"member \"name\" appears twice in one object, and a tree's events hold each key once; --whole reads the document whole","path":".name","output":"none"}
1

The failure's path says where the repeated key is.

Read the document whole #

Add --whole. dmog reads the entire document first, takes the value the format's own reading gives it, and writes that:

$ dmog translate --from json --to yaml --whole repeated.json
"name": "second"

For JSON, the last value of a repeated key wins.

A YAML file of several documents becomes an array of them:

$ dmog translate --from yaml --to json --whole two-documents.yaml
[{"title":"one"},{"title":"two"}]

What to watch for #

--whole holds the whole document in memory before writing a byte. Use it for the documents that need it, not as a default, since a large file then costs memory in proportion to its size.

A refusal of this kind can come part way through a document, after some output has been written. The failure then says "output":"partial". For why dmog streams at all, see Why dmog streams.

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