In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how to use the jq tool for parsing json format under linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The jq tool for parsing json format under linux the jq tool will read the json file better. In addition, the jq tool also checks the validity of the json file behind the back. if there is a format error in the file, jq will also report the location where the error exists. Chapter 1, introduction to jq, installation of jq tools under linux use jq tool in sudo apt-get install jq-yvim
Be careful to back up the json file in advance, as this operation will modify the file directly
Used in the last line mode of vim
:%! jq'. Chapter II basic use of the jq tool under linux 1. Check the validity of the format of the json file. If there is an error in the format of the json file, it will report the location of the error, such as: "url" parse error: Expected string key before':'at line 1, column 62, display all the contents of the json file cat json | jq. 3, get the value of Value through Key | jq '.name'
When parsing an element key that does not exist, it returns null.
4. Nested parsing
Case 1
Cat json_area.txt | jq '.location.state' "Beijin"
Case 2
$cat jsondemo [{"sha": "7b81a836c31500e685d043729259affa8b670a87", "commit": {"author": {"name": "William Langford", "email": "wlangfor@gmail.com", "date": "2017-06-19T14:55:26Z"}] $cat jsondemo | jq'. [0] .sha'"7b81a836c31500e685d043729259affa8b670a87" 5, built-in function
Jq has some built-in functions, such as has,key, etc. The key function is used to obtain the Key in json.
Jq 'keys' json_file
Has determines whether there is a Key in the json file
Cat json_raw.txt | jq 'has ("name")' truecat json_raw.txt | jq 'has ("noexisted")' false Thank you for reading! this is the end of the article on "how to use the jq tool for parsing json format under linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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: 226
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.