Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use json.tool, a powerful Python tool under Linux

Shulou Source: shulou.com Published: 2022-06-02 21:47:41 10月04日 Update

This article is to share with you about how to use json.tool, a powerful Python tool under Linux. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

Linux users often need to view some data in the terminal, read from the file or the network protocol to obtain the data and view. For example, look at the json data in the file; for example, look at the data stored in etcd.

If you look directly at the data obtained by cat or curl, it will be very painful if the format is confused, and the json.tool of Python can format the data in the terminal.

Such as: cat json.file | python-m json.tool

Usage and examples

# Terminal operation. Vim json.file # writes the following: {"code": 0, "data": "fine", "error": "success"}

What cat json.file sees at this point is:

{"code": 0, "data": "fine", "error": "success"}

Whatever is written in it, so be it!

Try using this tool at this time

# Terminal executes cat json.file | python-m json.tool # will see something like this: {"code": 0, "data": "fine", "error": "success"}

Next, try to check the data of etcd.

# curl directly: curl localhost:2379/v2/keys # get this {"action": "get", "node": {"dir": true, "nodes": [{"key": "/ NSQMetaData", "dir": true, "modifiedIndex": 5, "createdIndex": 5}, {"key": "/ b2c_systech_nsq", "dir": true, "modifiedIndex": 6726335, "createdIndex": 6726335}, {"key": "/ hello", "value": "world" "modifiedIndex": 4, "createdIndex": 4}]} # plus tool curl localhost:2379/v2/keys | python-m json.tool # get this {"action": "get", "node": {"dir": true, "nodes": [{"createdIndex": 5, "dir": true, "key": "/ NSQMetaData", "modifiedIndex": 5}, {"createdIndex": 6726335, "dir": true "key": "/ b2c_systech_nsq", "modifiedIndex": 6726335}, {"createdIndex": 4, "key": "/ hello", "modifiedIndex": 4, "value": "world"}]}}

It can be seen that this gadget is still very helpful in the terminal environment and is worth learning.

The above is how to use json.tool, a powerful Python tool under Linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Data tools terminals content power files more format knowledge articles practical great painful and then work meetings articles environment users look. Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology NVidia Apple Linux