Ways to process JSON data at the shell command line _linux Shell

Source: Internet
Author: User

Because I've been working on some JSON data formats recently, I finally found JQ this great tool after a search. JQ allows you to manipulate JSON directly under the command line, including slicing, filtering, converting, and so on.
Let's use a few examples to illustrate the JQ features:
one, the output format, the beautiful printing effect
if we turn on JSON with a text editor, sometimes it might look like a mess, but with the JQ. (dot) filter, you can immediately get the format of the JSON formatted.
1. When opened with a text editor

2. Results displayed with JQ

Copy Code code as follows:
% JQ. Soundtag.json


second, quickly query JSON data
Using JQ, you can make quick queries to JSON with key as a keyword, for example:
Copy Code code as follows:
% JQ. CN Soundtag.json

This will only show the value corresponding to the CN key.
JQ's key query also supports chained calls, such as:
Copy Code code as follows:
% JQ. Cn[0].pnum Soundtag.json

third, the JQ pipeline operation
Friends who are familiar with the command line may know | (pipeline) is a very powerful weapon. Fortunately, JQ also provides support for the pipeline.
Copy Code code as follows:
% JQ '. cn[] | {Pnum} ' Soundtag.json

Here, we use the pipe to filter and construct the Pnum object.
Iv. Summary
If you need to process JSON at the command line, I strongly recommend JQ. JQ can not only meet the common requirements, but also include operations, built-in functions, conditional comparisons, variable declarations, custom functions, and other powerful functions. Friends interested in this, may wish to learn through the Official Handbook of JQ.

PS: About JSON operation, here we recommend a few more practical JSON online tools for your reference to use:

Online JSON code inspection, inspection, landscaping, formatting tools:
Http://tools.jb51.net/code/json

JSON Online formatting tool:
Http://tools.jb51.net/code/jsonformat

Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson

JSON code online Format/beautify/compress/edit/Convert tools:
Http://tools.jb51.net/code/jsoncodeformat

Online JSON compression/escape tool:

Http://tools.jb51.net/code/json_yasuo_trans

C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json

Related Article

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.