Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac cli to convert yaml to json

Tags:

json

yaml

is there a quick way to convert bunch of yaml files to json files. I looked at yaml2json and it is not working (throws some exception)

Thanks

like image 877
Rajesh Jain Avatar asked Sep 11 '25 08:09

Rajesh Jain


2 Answers

Adding answer because there's no answer for the latest version for yq (except in comments).

brew install yq

yq -j eval test.yaml

Or, newer syntax:

yq -o=json eval test.yml
like image 69
amay Avatar answered Sep 13 '25 03:09

amay


Use the real yq (not python yq) from https://github.com/mikefarah/yq

brew reinstall yq

Then run:

/usr/local/bin/yq eval deployment.yaml -o=json -P > deployment.json

Meaning of the arguments, from --help:

  -P, --prettyPrint           pretty print, shorthand for '... style = ""'
  -o, --output-format string  [yaml|y|json|j|props|p|xml|x] output format type. (default "yaml") 
like image 29
Rajesh Jain Avatar answered Sep 13 '25 03:09

Rajesh Jain