allow serializing multidoc jq output back into yaml
Closed this issue · 0 comments
clux commented
consider this command that provides multidoc of json as jq output:
$ cat test/deploy.yaml | yq '.[].metadata' -c
{"name":"controller","namespace":"default"}
{"name":"controller"}
{"name":"controller"}
{"labels":{"app":"controller"},"name":"controller","namespace":"default"}
{"labels":{"app":"controller"},"name":"controller","namespace":"default"}
what if we want this in yq output?
we'd currently have to do compact output and pass each line to yq.
we should be able to just pass -y
to the above query, but that fails;
Error: trailing characters at line 5 column 1
we need to try to speculatively parse jq output in the same way we read the input yaml; by iterating over the Deserializer
, and;
- if it has exactly one entry; deserialize into a
serde_json::Value
- if it has many entries; deserialize into a
Vec<serde_json::Value>
(zero entries get an empty vec)
and after that convert it to yaml.