When following the example to display YAML from a JSON file, only JSON is displayed.
$ cat sample.json
{"a":"Easy! as one two three","b":{"c":2,"d":[3,4]}}
$ yq r sample.json
{"a": "Easy! as one two three", "b": {"c": 2, "d": [3, 4]}}
a: Easy! as one two three
b:
c: 2
d:
- 3
- 4
$ yq --version
yq version 3.0.0-beta
Ah this is because the latest version of yq tries to keep the original document format, and JSON is a subset of YAML - so the format does not change
Retaining the format is also nice :-) How about a parameter to convert back to YAML?
Adding a +1 to this, I use YQ v2 often to create an idiomatic YAML from a JSON, often as part of a pipeline after JQ. For instance, to decode the values in Kubernetes secret:
kubectl get secret mysecret -o json |
jq '{ apiVersion, kind, metadata: (.metadata | { name, namespace }), data: (.data | with_entries(.value |= (. | @base64d))) }' |
yq r -
And the result is (was) formatted as YAML, which JQ won't do for me. As of v3, the pretty output has gone 馃槶.
Latest (master) has a pretty print flag to the read command - it will go in the next release :)
It's still broken on 3.0.1, and apparently master has a fix, so @mikefarah can we do a release ASAP ? thanks
Adding a +1 to this. still it is not working properly in version 3.0.1
Done! See https://github.com/mikefarah/yq/releases/tag/3.1.0 and the pretty print docs https://mikefarah.gitbook.io/yq/usage/output-format#pretty-print
Most helpful comment
Retaining the format is also nice :-) How about a parameter to convert back to YAML?