How to Use the jq Command: Linux Bash, PowerShell with Examples
The jq is a powerfull tool designed for working with JSON(JavaScript Object Notation) data. JSON is commonly used for storing and transmitting data in web applications, APIs and configurations. To learn JSON in dept click here..
jq allows you to parse, filter and manipulate JSON data from the command line, making it very useful for developers/system administrators. It can make raw json data into more prettier and human readable.
In this post we cover jq essentials from scratch -
Table of contents :
- Installation
- Basic uses of jq
- examples
- how to acces element of an array
- conclusion
1. Installation
- Using Winget - winget install jqlang.jq
- Using Scoop - scoop install jq
- Using Chocolatey NuGet - choco install jq
1.1 Install jq on windows :
- On Debian/Ubuntu - sudo apt-get install jq
- On Arch - sudo pacman -S jq
- On Fedora - sudo dnf install jq
1.2 Install jq on Linux :
- Using Homebrew - brew install jq
- Using Flink - fink install jq
- Using MacPorts - port install jq
1.3 Install jq on MacOs :
2. Basic uses of jq
- To prettify a json file use jq command , we can use '.' filter which gives a pretty and human readable output of given json file.
- The command would be :
jq '.' file.json
. It will give and pretty json output which can be redirected/save into anthor file.