scene
- Linux users often need to view some data in the terminal, from the file or network protocol to get data and view. For example, view the json data in the file; for example, view the data saved in etcd.
- If you look directly at the data from cat or curl, it will be painful if the format is scrambled, while python's json. tool can format the data in the terminal. For example: cat json.file | Python - M json.tool
Usage and examples
# Terminal operation, vim json.file # Write the following: {"code": 0,"data": "fine","error": "success"}
What cat json.file sees at this time is:
{ "code": 0,"data": "fine","error": "success" }
Write in what kind, what kind!
Try this tool at this time.
#Terminal execution cat json.file | python -m json.tool # What you see becomes this: { "code": 0, "data": "fine", "error": "success" }
Next, try the data view of etcd.
# Just curl: 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}]}} # Add tools 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 the help of this gadget in the terminal environment is still great, which is worth learning.