Use jq-friendly JSON printing skills in Linux and linuxjqjson skills

Source: Internet
Author: User

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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.