Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to process JSON data on the Shell command line

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report