Use jq-friendly JSON printing skills in Linux and linuxjqjson skills
Previously, Cat was used to print JSON under the command line, and the results were copied to the editor supporting JSON parsing.
After a simple search, I found an article on StackOverflow. The answer with the highest support rating needs Python2.6 + support, but the version on the server is 2.4. The impact after the upgrade is unpredictable, so I gave up.
Let's continue to look at the answer below. A small tool named jq looks pretty good. The download test can indeed meet the requirements.
# Cat food. json | jq '.'
You can get the formatted result.
Let's introduce jq in detail.
Jq Official Website: http://stedolan.github.io/jq/
Download binary can be called directly, detailed installation can be seen in: http://stedolan.github.io/jq/download/
Simple usage:
1. Friendly display of json files
Copy codeThe Code is as follows:
Cat jsonfile | path_to_jq/jq.
2. Obtain the value of a json key.
Copy codeThe Code is as follows:
Cat jsonfile | path_to_jq/jq ". key"
For more operations, see: http://stedolan.github.io/jq/manual/