Linux命令行(Console)解析JSON

简介: 有些Linux服务API返回的数据为JSON数据,但是直接在命令行看,看起来很不方便,都拧巴在一起了,比如这样。[root@songshucang nginx]# curl http://localhost:8500/v1/catalog/servi...

有些Linux服务API返回的数据为JSON数据,但是直接在命令行看,看起来很不方便,都拧巴在一起了,比如这样。

[root@songshucang nginx]# curl http://localhost:8500/v1/catalog/service/xxx
[{"ID":"5c82060b-caa6-082c-27ac-4e64d38d35f1","Node":"izwz99ridy7gp33ry7hmfqz","Address":"172.18.177.227","Datacenter":"default","TaggedAddresses":{"lan":"172.18.177.227","wan":"172.18.177.227"},"NodeMeta":{"consul-network-segment":""},"ServiceID":"application-ecs-8090","ServiceName":"songshu-cang","ServiceTags":["songshu"],"ServiceAddress":"172.18.177.227","ServicePort":8090,"ServiceEnableTagOverride":false,"CreateIndex":502,"ModifyIndex":502},{"ID":"5c82060b-caa6-082c-27ac-4e64d38d35f1","Node":"izwz99ridy7gp33ry7hmfqz","Address":"172.18.177.227","Datacenter":"default","TaggedAddresses":{"lan":"172.18.177.227","wan":"172.18.177.227"},"NodeMeta":{"consul-network-segment":""},"ServiceID":"application-ecs-8091","ServiceName":"songshu-cang","ServiceTags":["songshu"],"ServiceAddress":"172.18.177.227","ServicePort":8091,"ServiceEnableTagOverride":false,"CreateIndex":520,"ModifyIndex":520}][root@songshucang nginx]#

不过Linux内置了一些命令,比如jq

[root@songshucang nginx]# yum info jq
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : jq
Arch        : x86_64
Version     : 1.5
Release     : 1.el7
Size        : 351 k
Repo        : installed
From repo   : epel
Summary     : Command-line JSON processor
URL         : http://stedolan.github.io/jq/
License     : MIT and ASL 2.0 and CC-BY and GPLv3
Description : lightweight and flexible command-line JSON processor
            :
            :  jq is like sed for JSON data – you can use it to slice
            :  and filter and map and transform structured data with
            :  the same ease that sed, awk, grep and friends let you
            :  play with text.
            :
            :  It is written in portable C, and it has zero runtime
            :  dependencies.
            :
            :  jq can mangle the data format that you have into the
            :  one that you want with very little effort, and the
            :  program to do so is often shorter and simpler than
            :  you'd expect.

安装与使用jq

sudo yum install jq -y
img_1c8d229764635ccdb8e96d36c40352e3.png
使用jq

总结

简单的介绍了一个Linux的命令。

目录
相关文章
|
24天前
|
JSON JavaScript 前端开发
C++ 智能指针与 JSON 处理:高级编程技巧与常见问题解析
C++ 智能指针与 JSON 处理:高级编程技巧与常见问题解析
254 0
|
8天前
|
Linux
Linux命令行快捷键
Linux命令行快捷键
|
24天前
|
JSON JavaScript 数据格式
【深入探究C++ JSON库】解析JSON元素的层级管理与遍历手段
【深入探究C++ JSON库】解析JSON元素的层级管理与遍历手段
78 2
|
24天前
|
XML JSON API
深入解析C++ JSON库:nlohmann::json:: parse的内部机制与应用
深入解析C++ JSON库:nlohmann::json:: parse的内部机制与应用
42 0
|
27天前
|
存储 Shell Linux
【Shell 命令集合 系统设置 】Linux 将参数作为命令行输入 eval命令 使用指南
【Shell 命令集合 系统设置 】Linux 将参数作为命令行输入 eval命令 使用指南
25 0
|
29天前
|
JSON 数据格式
人脸检测解析json的工具类face_test
人脸检测解析json的工具类face_test
13 0
|
29天前
|
机器学习/深度学习 编解码 API
FFmpeg命令行解析
FFmpeg命令行解析
65 1
|
1月前
|
JSON JavaScript 前端开发
如何在Python中解析JSON响应?
【2月更文挑战第26天】【2月更文挑战第92篇】如何在Python中解析JSON响应?
|
1月前
|
Linux Shell
Linux命令行快捷键和技巧
Linux命令行快捷键和技巧
24 0
|
6月前
|
安全 Linux Shell
1.Linux 命令行快捷键介绍
1.Linux 命令行快捷键介绍