Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active April 26, 2024 21:23
Show Gist options
  • Save zulhfreelancer/2530bbd7453920455584660629ab1fcd to your computer and use it in GitHub Desktop.
Save zulhfreelancer/2530bbd7453920455584660629ab1fcd to your computer and use it in GitHub Desktop.
How to convert YAML to JSON using yq?

How to convert YAML to JSON using yq?

FYI, I'm using yq version 4 by mikefarah

Command:

cat <YAML-FILE-NAME> | yq e -j

Example:

cat config.yaml | yq e -j

Reference:

https://mikefarah.gitbook.io/yq/v/v4.x/

@zulhfreelancer
Copy link
Author

zulhfreelancer commented Aug 3, 2023

If mikefarah/yq isn't your thing, try kislyuk/yq.

Command:

cat <YAML-FILE-NAME> | yq

Example:

cat config.yaml | yq

@hegerdes
Copy link

How to convert YAML to JSON using yq?

FYI, I'm using yq version 4 by mikefarah

Command:

cat <YAML-FILE-NAME> | yq e -j

As of version v4.16 I'm getting a deprecation warning that -j or --tojson.

You should use -o json instead:

cat <YAML-FILE-NAME> | yq e -o json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment