gron icon indicating copy to clipboard operation
gron copied to clipboard

[suggestion] support YAML as well

Open iMartyn opened this issue 6 years ago • 5 comments

Given that YAML is a superset of JSON, and often things that are described in YAML are completely translatable to JSON (I'm thinking specifically Kubernetes manifests but there are others), a -y option to parse yaml (especially useful if it worked with ungron) would be kinda nifty.

Of course that adds to #35 complications and #23 #28 as yaml spec specifically specifies multiple YAML docs per file, but anyway, just a thought.

iMartyn avatar Nov 13 '18 23:11 iMartyn

As a workaround, I've found yq to be helpful in certain cases.

You can use yq r - -j to read stdin and convert to JSON before piping to gron

thesurlydev avatar Sep 20 '20 22:09 thesurlydev

Yeah, that's what I'm doing myself, but given it's very easy to add yaml support (there's even a PR open now), saving a pipe in the complex one-liners is a good thing(tm) in my book :-)

iMartyn avatar Sep 21 '20 07:09 iMartyn

It seems that yq is capable of handling gron's duties with the -o=p parameter. Also, it support YAML out of the box.

jarda-wien avatar Oct 19 '21 11:10 jarda-wien

It seems that yq is capable of handling gron's duties with the -o=p parameter. Also, it support YAML out of the box.

Example from gron's README:

curl -s "https://api.github.com/repos/tomnomnom/gron/commits?per_page=1" | ./yq_linux_amd64 eval -o=p | grep commit.author
0.commit.author.name = Tom Hudson
0.commit.author.email = [email protected]
0.commit.author.date = 2020-11-07T01:17:42Z

jarda-wien avatar Oct 19 '21 11:10 jarda-wien

How would you show the comments? Just omit them? I think it would be cool to try to preserve them. The comments on the same line on the same line, the comments above a node above a node I figure, and any comments at the end of the file at the end of the file.

YAML is used a lot - Kubernetes, GitLab CI, GitHub Actions, and so on... The attempts to improve on it so far get rid of things I like about YAML.

There's also JSON with comments, a format which I'm opposed to, but which sees a lot of use by M$. It might be worth supporting that so people can grep their vscode configs. I still fiddle with them sometimes at the moment in VSCodium, though I'm hoping for an alternative that among other things wouldn't use JSON with comments, which isn't JSON. https://www.ietf.org/rfc/rfc4627.txt

benatkin avatar Feb 06 '23 00:02 benatkin