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:
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:
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