How to format json data in linux (Fedora / Centos / RHEL)?

How to format json data in linux (Fedora / Centos / RHEL)?

We can align any json text using jq tool in linux.

this jq shell command is used to format and view json data in linux

$ cat test.json | jq .

Output:

bash: jq: command not found...

How to install jq tool in linux?

$ yum install jq

Output:

Error: This command has to be run under the root user.

try using sudo or as root user,

$ sudo yum install jq

Output:

Extra Packages for Enterprise Linux 7 - x86_64                                                                                            	26 kB/s |  32 kB 	00:01    
Fedora Modular 29 - x86_64                                                                                                               	4.7 kB/s | 5.1 kB 	00:01    
Fedora Modular 29 - x86_64 - Updates                                                                                                     	4.5 kB/s | 5.0 kB 	00:01    
Fedora 29 - x86_64 - Updates                                                                                                             	5.0 kB/s | 5.0 kB 	00:00    
Fedora 29 - x86_64                                                                                                                       	5.1 kB/s | 5.1 kB 	00:01    
google-chrome                                                                                                                            	6.8 kB/s | 1.3 kB 	00:00    
rdopkg for Fedora 29                                                                                                                     	212  B/s | 341  B 	00:01    
Failed to synchronize cache for repo 'rdopkg'
RCM Tools for Fedora 29 (RPMs)                                                                                                           	5.5 kB/s | 3.8 kB 	00:00    
Ignoring repositories: rdopkg
Dependencies resolved.
=============================================================================================================================================================================
 Package                               	Architecture                       	Version                                  	Repository                           	Size
=============================================================================================================================================================================
Installing:
 jq                                    	x86_64                             	1.6-2.el7                                	epel                                	167 k
Installing dependencies:
 oniguruma                             	x86_64                             	6.9.1-3.fc29                             	updates                             	193 k

Transaction Summary
=============================================================================================================================================================================
Install  2 Packages

Total download size: 360 k
Installed size: 1.1 M
Is this ok [y/N]: y
Downloading Packages:
Extra Packages for Enterprise Linux 7 - x86_64                 	840% [==============================================================================================================================================================================================================================================================================================================================================================================================================================================================Fedora 29 - x86_64 - Updates                                   	840% [==============================================================================================================================================================================================================================================================================================================================================================================================================================================================Fedora 29 - x86_64 - Updates                                   	731% [==============================================================================================================================================================================================================================================================================================================================================================================================================================================================(1/2): jq-1.6-2.el7.x86_64.rpm                                                                                                           	179 kB/s | 167 kB 	00:00    
(2/2): oniguruma-6.9.1-3.fc29.x86_64.rpm                                                                                                  	87 kB/s | 193 kB 	00:02    
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                     	73 kB/s | 360 kB 	00:04	 
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing    	:                                                                                                                                                 	1/1
  Installing   	: oniguruma-6.9.1-3.fc29.x86_64                                                                                                                   	1/2
  Running scriptlet: oniguruma-6.9.1-3.fc29.x86_64                                                                                                                   	1/2
  Installing   	: jq-1.6-2.el7.x86_64                                                                                                                             	2/2
  Running scriptlet: jq-1.6-2.el7.x86_64                                                                                                                             	2/2
  Verifying    	: jq-1.6-2.el7.x86_64                                                                                                                             	1/2
  Verifying    	: oniguruma-6.9.1-3.fc29.x86_64                                                                                                                   	2/2

Installed:
  jq-1.6-2.el7.x86_64                                                          	oniguruma-6.9.1-3.fc29.x86_64                                                        	 

Complete!

Let's try again,

$ cat test.json | jq .

Output:

{
  "employees": [
	{
  	"name": "A",
  	"salary": 10000,
  	"sex": "male",
  	"age": 41
	},
	{
  	"name": "B",
  	"salary": 20000,
  	"sex": "male",
  	"age": 26
	}
  ]
}



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
^