Because some JSON data formats are to be processed recently, after some searches, we finally found jq, a great tool. Jq allows you to operate JSON directly on the command line, including sharding, filtering, conversion, and so on.
Let's use several examples to illustrate jq's functions:
Beautiful print
If we use a text editor to open JSON, it may sometimes look messy,.
(Point) the filter can immediately adjust the JSON format.
% jq . soundtag.json
How it looks after it is opened in a text editor
Result displayed with jq
Quick query
With jqkey
As a keyword to make a quick query of JSON, for example:
% jq .cn soundtag.json
This will only showcn
The value corresponding to the key.
Jq key query also supports chained calling, such:
% jq .cn[0].pNum soundtag.json
MPs queue operations
Anyone familiar with command lines may know that | (pipeline) is a very powerful weapon. Fortunately, jq also provides support for pipelines.
% jq '.cn[] | { pNum }' soundTag.json
Here, we use pipelines to filter and construct pNum objects.
Summary
If you need to process JSON in the command line, I strongly recommend jq. Jq not only meets common general requirements, but also provides powerful functions such as computation, built-in functions, condition comparison, variable declaration, and custom functions. If you are interested in this, you may wish to learn through the official jq manual.
Recommended reading:
Send XML and JSON data asynchronously in Struts
Compiling and code testing of the JSON library in Linux
JQuery retrieves JSON data [$. getJSON method]
Convert form data into JSON strings using jQuery and JSON packages