Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Is there something similar for YAML? I've tried `yq` briefly but weirdly enough it doesn't seem to accept standard input in the way that jq does (ie pipe in some json, and output some pretty json)


Highly recommend https://github.com/mikefarah/yq

It can do everything with json as well and convert between


Worth noting OP has tried it and has some critiques.

> I've tried `yq` briefly but weirdly enough it doesn't seem to accept standard input in the way that jq does (ie pipe in some json, and output some pretty json)




it shouldn't be too difficult to convert between yaml and json, funny i couldn't find a light weight converter easily. I think i will try to write one.


Doesn't yaml have significantly more baggage as far as "advanced features" that couldn't be properly duplicated in json?


Basic YAML, sure, but YAML has some insane features that I don't think would be possible to replicate in JSON. Or, at least, you'd lose some information in the conversion.

For example, YAML supports the concept of reusable fragments. You can define a fragment in one place and reference it further down in your YAML file. A JSON converter could take the final YAML output and turn it into JSON but you would lose the context of the fact that in the original YAML it was an included fragment and not just the same section repeated a few times.


Yeah, YAML can also embed arbitrary code in the original Ruby incarnation and that clearly cannot be translated to JSON.

Yeah, no straightforward translation of references to JSON. You could provide both translation ramps, but it would be an implementation-specific convention and not something other JSON tools understood.


jc has a yaml to json converter:

cat file.yaml | jc --yaml


yq r test.json > test.yaml

yq r -j test.yaml > test.json




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: