yq Command-line YAML processor

yq Command-line YAML processor

how to install yq package in RHEL8?

How to install yq using pip3 command in RHEL8 / Fedora / Centos

$ sudo pip3 install yq

Output:

WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting yq
  Downloading https://files.pythonhosted.org/packages/a6/82/c684e796cf1ed351a76439f006534853a1bd47f6df6b55d6906801be8700/yq-2.11.0-py2.py3-none-any.whl
Collecting argcomplete>=1.8.1 (from yq)
  Downloading https://files.pythonhosted.org/packages/89/4d/b8e035cca2c9b2484ac12d20e0fb68019e17f0b09918f2765e0a381127fb/argcomplete-1.12.0-py2.py3-none-any.whl
Requirement already satisfied: PyYAML>=3.11 in /usr/lib64/python3.6/site-packages (from yq)
Requirement already satisfied: setuptools in /usr/lib/python3.6/site-packages (from yq)
Collecting xmltodict>=0.11.0 (from yq)
  Downloading https://files.pythonhosted.org/packages/28/fd/30d5c1d3ac29ce229f6bdc40bbc20b28f716e8b363140c26eff19122d8a5/xmltodict-0.12.0-py2.py3-none-any.whl
Collecting importlib-metadata<2,>=0.23; python_version == "3.6" (from argcomplete>=1.8.1->yq)
  Downloading https://files.pythonhosted.org/packages/8e/58/cdea07eb51fc2b906db0968a94700866fc46249bdc75cac23f9d13168929/importlib_metadata-1.7.0-py2.py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata<2,>=0.23; python_version == "3.6"->argcomplete>=1.8.1->yq)
  Downloading https://files.pythonhosted.org/packages/c4/79/3b770d51254a31bb85ba56ea70d7428d0c2c659a233cc9722352e028b539/zipp-3.2.0-py3-none-any.whl
Installing collected packages: zipp, importlib-metadata, argcomplete, xmltodict, yq
Successfully installed argcomplete-1.12.0 importlib-metadata-1.7.0 xmltodict-0.12.0 yq-2.11.0 zipp-3.2.0

What is yq?

It is an command-line YAML processor and also provides jq wrapper for YAML documents.

yq transcodes YAML documents to JSON and passes them to jq.

Let us consider the sample json file,

$ cat  test.json
{
"param1": [ "1", "2", "3"],
"param2": "testing"
}

Let us use yq command, what is the json output?

here dot(.) indicates the entire json data will be consider to parse.

$ cat  test.json | yq .

yq . just translates the json or yaml document into JSON format.

Output:

{
  "param1": [
	"1",
	"2",
	"3"
  ],
  "param2": "testing"
}

How to convert JSON document into YAML format?

>

Need to use option as any of the below format.

--yaml-output, --yml-output, -y

We need to use -y to transcode jq JSON output back into YAML and emit it

$ cat  test.json | yq -y .

Output:

param1:
  - '1'
  - '2'
  - '3'
param2: testing

We can also directly use file name in the command to get YAML format data.

$ yq -y . test.json

Output:

param1:
  - '1'
  - '2'
  - '3'
param2: testing




Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^