How To - View a JSON file from a TAR and Gzipped file in your Terminal
This is a very handy trick for viewing a JSON file located in a TAR and Gzipped file. Many docker applications are TAR and Gzipped, and you often want to view the manifest JSON file.
Normally, we would need to extract everything and then open the file.
This quick trick allows you to read that file directly from the Terminal with all the formatting. First, make sure your Linux distro has both tar and jq installed.
First, we need to know the name of the file we want to open. Let’s print the file content on the terminal.
Command:
tar -t -f ./hello-world.tar.gz
Output
247460e92ef67fdf643394f29fdfdfcec2fde609010ec63e3b7bee779e1a4846/
247460e92ef67fdf643394f29fdfdfcec2fde609010ec63e3b7bee779e1a4846/VERSION
247460e92ef67fdf643394f29fdfdfcec2fde609010ec63e3b7bee779e1a4846/json
247460e92ef67fdf643394f29fdfdfcec2fde609010ec63e3b7bee779e1a4846/layer.tar
7b473dec0fa9e1cd2ffeb04ca39b125972ca0927000ccd033404674671768b8a/
7b473dec0fa9e1cd2ffeb04ca39b125972ca0927000ccd033404674671768b8a/VERSION
7b473dec0fa9e1cd2ffeb04ca39b125972ca0927000ccd033404674671768b8a/json
7b473dec0fa9e1cd2ffeb04ca39b125972ca0927000ccd033404674671768b8a/layer.tar
d68fcc334f453a8c889c682226e6c6dc39694eaa4af54fdc8cc03bba03fdbb1c.json
manifest.json
repositories
We can see the file we will want to open and view is called “manifest.json”. To view it in all its glory, we will need to run this command:
Command:
tar -x -O -f ./hello-world.tar.gz manifest.json | jq
Output:
The command tells it to open only the “manifest” file and then open it with the jq utility, which will format the JSON data nicely.
I think you will be pretty amazed at how fast and well these commands work. Try it, and let me know what you think!