In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to print JSON files on Linux terminals. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
JSON is a text format that is completely independent of the programming language and is a lightweight data exchange format. The introduction and clarity of JSON make it the most ideal data exchange language.
The computer can read it easily. Even people can read it, but if the JSON file is displayed in the right format, it will be much easier to read. I mean, the JSON file should be read like this:
Pretty Printed JSON is easier to read
You can use most text editors and some plug-ins to display it in the appropriate format. However, if you are in the terminal, or if you want to do this in your shell script, things will be different.
If you have a minimized JSON file, let me show you how to output it beautifully in a Linux terminal.
Print the JSON file beautifully with the jq command in Linux
Jq is a command line JSON processor. You can use it to split, filter, map, and transform structured data. I'm not going to cover the use of jq command-line tools in detail here.
To use jq, you need to install it first. You can use your distribution's package manager to install it. If the universe repository is enabled, you can install it on Ubuntu using the apt command:
Sudo apt install jq
After installation, print the JSON file beautifully on the display screen using the following methods:
Jq. Sample.json
Pretty printed JSON file
You may also want to use cat, but I don't think cat is useful here.
Cat sample.json | jq
Keep in mind that the above command does not affect the original JSON file. No changes are written to it.
You may already know how to redirect command output to a file in Linux. You probably know that you can't redirect to the same file, and the tee command is not guaranteed to last forever.
If you want to modify the original JSON file in a beautiful format, you can pipe the parsed output to a new file, and then overwrite the original JSON file.
Jq. Sample.json > pretty.json
Pretty printing JSON file in Linux Terminal
Extra tip: use the jq command to minimize JSON files.
Let's turn around and minimize a well-formed JSON file. To minimize JSON files, you can use the option-c.
Jq-c Minified JSON file display if you like, you can also use cat and redirect: cat pretty.json | jq-c uses Python in Linux to beautifully print JSON files and you are more likely to have Python installed on your system. If this is the case, you can use it to print JSON files beautifully in the terminal: python3-m json.tool sample.jsonPretty printing JSON with Python on "how to print JSON files on Linux terminals" this article is shared here, 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, please share it out 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: 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.
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.