kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.57k stars 82 forks source link

--slurpfile doesn't work with yaml files #122

Closed schra closed 3 years ago

schra commented 3 years ago

I would expect this to work:

$ cat test.yaml
{foo: bar}

$ yq --slurpfile test test.yaml . test.yaml
jq: Bad JSON in --slurpfile test test.yaml: Invalid literal at line 1, column 5

It works with jq:

$ cat test.json
{"foo": "bar"}

$ jq --slurpfile test test.json . test.json
{
  "foo": "bar"
}

More information:

$ yq --version
yq 2.12.0

$ jq --version
jq-1.5-1-a5b5cbe
kislyuk commented 3 years ago

yq is a wrapper for jq. Options such as slurpfile are passed unmodified to jq, so the data they reference must be interpretable by jq. You can get around this by converting the input to slurpfile using yq as well:

yq . t.yml --slurpfile t <(yq . t.yml)

This actually did not work until today because of an unrelated problem (yq used the default Python 3 behavior of closing all fds except 0, 1 and 2 when spawning subprocesses). I fixed this issue and released v2.12.1, so please install that before using the recipe above.