Translate part of a document
Pick one value out of a document with --path and write only that value.
You need one value from a document, such as one section of a configuration file. --path names it.
Name the value #
A path is a JSON array. Each string is an object's key and each number is an array's index, from the root down:
$ dmog translate --from yaml --to json --path '["server"]' server.yaml
{"host":"example.com","port":8080,"tls":true}
$ dmog translate --from yaml --to json --path '["paths",1]' server.yaml
"/health"
Quote the path for the shell, with single quotes around it, so that the brackets and the double quotes reach dmog as written.
What to watch for #
dmog still reads the whole document, because a key may appear twice and the second one decides. It writes only the value the path names, as it reads it.
A path that names nothing fails with INPUT_INVALID once the document has been read, and writes nothing:
$ dmog translate --from yaml --to json --path '["client"]' server.yaml; echo $?
{"code":"INPUT_INVALID","message":"the path [\"client\"] names nothing in the document","output":"none"}
1
The value is written as a plain tree, whatever shape the source gave it. For the exact form a path takes, see --path.