How to process JSON data on the Shell command line
This article focuses on "how to deal with JSON data on the Shell command line". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to deal with JSON data on the Shell command line.
First, the output format, beautiful printing effect
If we open JSON with a text editor, it may sometimes look like a mess, but through jq's. (dot) filter, you can immediately format JSON.
1. What it looks like when you open it with a text editor
two。 Results displayed in jq
The code is as follows:
% jq. Soundtag.json
Second, quickly query JSON data
Using jq, you can use key as the keyword to query JSON quickly, for example:
The code is as follows:
% jq .cn soundtag.json
This will display only the value corresponding to the cn key.
Jq's key query also supports chained calls, such as:
The code is as follows:
Jq .cn [0] .pNum soundtag.json
III. Pipeline operation of jq
Friends who are familiar with the command line may know that | (pipe) is a very powerful weapon. Fortunately, jq also provides support for pipelines.
The code is as follows:
% jq '.cn [] | {pNum}' soundTag.json
Here, we use pipes to filter and construct pNum objects.
At this point, I believe you have a deeper understanding of "how to deal with JSON data on the Shell command line". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!