Yq: Unable to display YAML from JSON file

Created on 28 Jan 2020  路  7Comments  路  Source: mikefarah/yq

When following the example to display YAML from a JSON file, only JSON is displayed.

Steps to reproduce

$ 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]}}

Expected output

a: Easy! as one two three
b:
  c: 2
  d:
  - 3
  - 4

Details

$ yq --version
yq version 3.0.0-beta

Most helpful comment

Retaining the format is also nice :-) How about a parameter to convert back to YAML?

All 7 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jmreicha picture jmreicha  路  9Comments

ykfq picture ykfq  路  8Comments

andrewsav-bt picture andrewsav-bt  路  6Comments

infa-ddeore picture infa-ddeore  路  5Comments

jmreicha picture jmreicha  路  5Comments